Encoding problems

Gandalf gandalf at geochemsource.com
Fri Sep 3 10:49:37 CEST 2004


> works, but unfortunately, it doesn't, as raw_input does not support
> Unicode. However, the encoding Python has determined is available
> as sys.stdout.encoding, so you can do
>
> bildschirm = raw_input(u"néz".encode(sys.stdout.encoding))
>
> This works even if the user has done chcp in the window, as Python
> queries the window what its encoding is, during Python startup. 

 >>>import sys
 >>>sys.stdout.encoding
'cp852'
 >>>sys.stdin.encoding
'cp852'

It is way strange!
I understand that  we need to do encoding for the output because strings 
in the program files needs to be encoded to the terminal's encoding 
before printing.
However, the input (the result of raw_input) will be in the correct 
encoding (iso-8859-2 in my case) without any conversion.
I do not understand why is that? The stdin encoding is cp852, not 
iso-8859-2.






More information about the Python-list mailing list