How does the print statement decode unicode strings itis passed ? (By
that I mean which encoding does it use).
Under windows it doesn't appear to use defaultencoding . On my system
the default encoding is ascii, yet the terminal encoding is latin1 (or
cp1252 or whatever, but not ascii). This means that print '£' works
fine, yet unicode('£') will raise the UnicodeDecodeEr ror.
However print u'£' will also work fine. (Under pythonce this same
statement raises a UnicodeDecodeEr ror - but the 'terminal' is
different).
In my understanding unicode is an 'internal representation' - if you
want to write a unicode string to a file you have to turn it into a
byte string and specify an encoding (unless you pickle it - which is
cheating). So when you 'print' a unicode string, what is sent to
sys.stdout ? Is a character encoding used ? If so which one... if
not... why not ?
(In this case if defaultencoding was used it *ought* to raise a
UnicodeDecodeEr ror).
Regards,
Fuzzy
http://www.voidspace.org.uk/python/index.shtml
that I mean which encoding does it use).
Under windows it doesn't appear to use defaultencoding . On my system
the default encoding is ascii, yet the terminal encoding is latin1 (or
cp1252 or whatever, but not ascii). This means that print '£' works
fine, yet unicode('£') will raise the UnicodeDecodeEr ror.
However print u'£' will also work fine. (Under pythonce this same
statement raises a UnicodeDecodeEr ror - but the 'terminal' is
different).
In my understanding unicode is an 'internal representation' - if you
want to write a unicode string to a file you have to turn it into a
byte string and specify an encoding (unless you pickle it - which is
cheating). So when you 'print' a unicode string, what is sent to
sys.stdout ? Is a character encoding used ? If so which one... if
not... why not ?
(In this case if defaultencoding was used it *ought* to raise a
UnicodeDecodeEr ror).
Regards,
Fuzzy
http://www.voidspace.org.uk/python/index.shtml
Comment