error when printing a UTF-8 string (python 2.6.2)

Terry Reedy tjreedy at udel.edu
Wed Apr 21 19:00:25 CEST 2010


On 4/21/2010 9:29 AM, Peter Otten wrote:
> python at bdurham.com wrote:
>
>> Are you saying all open() calls in Python that read text files,
>> automatically convert UTF-8 content to Unicode in the same manner as the
>> following might when using Python 2.6?
>>
>> codecs.open( fileName, mode='r', encoding='UTF8', ... )
>
>
> That's what I meant to say, but it's not actually true.

I wish it were, though.

> Quoting http://docs.python.org/py3k/library/functions.html#open
>
> """
> open(file, mode='r', buffering=None, encoding=None, errors=None,
> newline=None, closefd=True)
>
> [...]
>
> encoding is the name of the encoding used to decode or encode the file. This
> should only be used in text mode. The default encoding is platform dependent
> (whatever locale.getpreferredencoding() returns), but any encoding supported
> by Python can be used. See the codecs module for the list of supported
> encodings.
> """
>
> So it just happend to be UTF-8 on my machine.

Unfortunately, it is not on US Windows.

Terry Jan Reedy




More information about the Python-list mailing list