How to Get Terminal'S Character Encoding

How to set proper chracter encoding for GNU/Linux

Your default charset is Latin-1 (aka. ISO 8859-1). This charset does not seem to contain the character . Chances are your JVM runs with this default because your system is configured to use Latin-1. You make sure that both your system and your JVM use UTF-8.

See How to get terminal's Character Encoding

Which character encoding is the IPython terminal using?

IPython uses OEM code page in the interactive mode like any other Python console program:

In [1]: '\u2552'
ERROR - failed to write data to stream: <_io.TextIOWrapper name='<stdout>' mode=
'w' encoding='cp850'>
Out[1]:

In [2]: !chcp
Active code page: 850

The result changes if pyreadline is installed (it enables colors in the IPython console among other things):

In [1]: '\u2552'
Out[1]: '╒'

In [2]: import sys

In [3]: sys.stdout.encoding
Out[3]: 'cp850'

In [4]: !chcp
Active code page: 850

Once pyreadline has been installed, IPython's sys.displayhook writes the result to readline's console object that uses WriteConsoleW() Windows Unicode API that allows to print even unencodable in the current code page Unicode characters (to see them, you might need to configure a (TrueType) font such as Lucida Console in the Windows console).



Related Topics



Leave a reply



Submit