To print Unicode characters correctly, you need these things:
Python must know the source encoding to understand non-ASCII characters in the source code. Python 3 assumes UTF-8 unless told otherwise with a special comment at the top of the file, such as #coding: cp850
. Note that the source encoding and the terminal encoding don't have to be the same, and it is fine to use UTF-8 for the source encoding as long as the source file is actually saved in UTF-8.
The Unicode character must be supported by the console's encoding.
- The Unicode character must be supported by the console's font.
- Use Unicode strings. In Python 3
'string'
is a Unicode string. b'string'
is a byte string.
Since your error message indicates the console is using Code page 850, you will get a UnicodeEncodeError
if you try to print any characters not supported by that code page.
Try this. These are legal cp850
characters:
print('╔═╦═╗')
print('║ ║ ║')
print('╠═╬═╣')
print('║ ║ ║')
print('╚═╩═╝')
This should work for Python 3 on any console/IDE that supports line-draw characters. The US Windows console uses cp437
and European Windows often uses cp850
, but both define the characters and the console font supports them.