[Python-Dev] File encodings

Walter Dörwald walter at livinglogic.de
Tue Nov 30 20:26:36 CET 2004


Gustavo Niemeyer wrote:

> Hello Walter,
> 
>>>I don't see that as a good solution, since every Python software
>>>that is internationalizaed will have do figure out this wrapping,
>>>introducing extra overhead unnecessarily.
>>
>>This wrapping is probably necessary for stateful encodings. If you
>>had a sys.stdout.encoding=="utf-16", print would probably add the
>>BOM every time a unicode object is printed. This doesn't happen if
>>you wrap sys.stdout in a StreamWriter.
> 
> I'm not sure this is an issue for a terminal output stream, which
> is the case I'm trying to find a solution for. Otherwise, Python
> would already be in trouble for using this scheme in the print
> statement. Can you show an example of the print statement not
> working?

No, I can't. Python doesn't accept UTF-16 as encoding.

This works:
 > LANG=de_DE.UTF-8 python2.4
Python 2.4 (#1, Nov 30 2004, 14:16:24)
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-113)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> sys.stdout.encoding
'UTF-8'

This doesn't:
 > LANG=de_DE.UTF-16 python2.4
Python 2.4 (#1, Nov 30 2004, 14:16:24)
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-113)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> sys.stdout.encoding
'ANSI_X3.4-1968'

Bye,
    Walter Dörwald




More information about the Python-Dev mailing list