Trying to understand this moji-bake

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Jan 25 21:04:40 EST 2014


On Sat, 25 Jan 2014 17:08:56 +1100, Chris Angelico wrote:

> On Sat, Jan 25, 2014 at 3:37 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> But using Python 2.7, I get a really bad case of moji-bake:
>>
>> [steve at ando ~]$ python2.7 -c "print u'ñøλπйж'" ñøλÏйж
> 
> What's 2.7's default source code encoding? I thought it was ascii, but
> maybe it's assuming (in the absence of a magic cookie) that it's
> Latin-1.

I think that's it! Python 2.7 ought to raise a SyntaxError, since there's 
no source encoding declared, while Python 3.3 defaults to UTF-8 which is 
the same as my terminal. If there's a bug, it is that Python 2.7 doesn't 
raise SyntaxError when called with -c and there are non-ASCII literals in 
the source. Instead, it seems to be defaulting to Latin-1, hence the moji-
bake.

Thanks to everyone who responded!


-- 
Steven



More information about the Python-list mailing list