Character error in Python3

1

I have problems when executing the following code in Python:

#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import os, sys
sara1 = '░█▀▀▀█ ─█▀▀█ ░█▀▀█ ─█▀▀█'
sara2 = ' ▀▀▀▄▄ ░█▄▄█ ░█▄▄▀ ░█▄▄█'
sara3 = '░█▄▄▄█ ░█─░█ ░█─░█ ░█─░█'
print (sara1)
print (sara2)
print (sara3)

The problem I have is that the result I get on the screen is as follows:

ŠŠ¯¯¯Š -Š¯¯Š ŠŠ¯¯Š -Š¯¯Š
 ¯¯¯__ ŠŠ__Š ŠŠ__¯ ŠŠ__Š
ŠŠ___Š ŠŠ-ŠŠ ŠŠ-ŠŠ ŠŠ-ŠŠ

What could I do to show it correctly?

Pd: for the curious is a sample the name you add.

    
asked by Juan Vial 10.11.2018 в 20:09
source

1 answer

3

The encoding you are using, ISO 8859-15, better known as Latin-9, only has 256 characters; and those that you try to print are not among them. I think the solution is the one that the comrade points out in the comment: use the UTF-8.

It might look like this:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os, sys
sara1 = '░█▀▀▀█ ─█▀▀█ ░█▀▀█ ─█▀▀█'
sara2 = ' ▀▀▀▄▄ ░█▄▄█ ░█▄▄▀ ░█▄▄█'
sara3 = '░█▄▄▄█ ░█─░█ ░█─░█ ░█─░█'
print (sara1)
print (sara2)
print (sara3)

You can see the characters of the Latin 9 standard in this link

    
answered by 10.11.2018 в 22:04