Python and unicode

Martin v. Loewis martin at v.loewis.de
Mon Sep 20 22:19:37 CEST 2010


Am 20.09.2010 12:57, schrieb Dotan Cohen:
> On Mon, Sep 20, 2010 at 12:20, Peter Otten <__peter__ at web.de> wrote:
>> It may work by accident, if you declare it as UTF-8, because that is also
>> the default in Python 3.
>>
> 
> That does seem to be the case.
> 
> Thank you for the enlightenment and information.

It's as Peter says. Python really will ignore any encoding declaration
on the third or later line. This was added to the spec on explicit
request from Guido van Rossum.

It's still the case today. However, in Python 3, in the absence of an
encoding declaration, the file encoding is assumed to be UTF-8
(producing an error if it actually is not). So it worked for you
by accident.

Regards,
Martin



More information about the Python-list mailing list