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

Peter Otten __peter__ at
Wed Apr 21 09:29:33 EDT 2010

python at 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?
> fileName, mode='r', encoding='UTF8', ... )

That's what I meant to say, but it's not actually true.


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 

So it just happend to be UTF-8 on my machine.


More information about the Python-list mailing list