Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64752
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <oscar.j.benjamin@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'encoding': 0.05; '-*-': 0.07; 'sys': 0.07; 'utf-8': 0.07; 'coding:': 0.09; 'encoding:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '2.7': 0.14; '2.7.2': 0.16; 'cc:name:python list': 0.16; 'debian.': 0.16; 'declaration': 0.16; 'declared': 0.16; 'non-ascii': 0.16; 'skip:u 50': 0.16; 'syntaxerror:': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'url:peps': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'example': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'skip:" 30': 0.26; 'least': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'character': 0.29; 'message- id:@mail.gmail.com': 0.30; "skip:' 10": 0.31; '>>>>': 0.31; "d'aprano": 0.31; 'occurs': 0.31; 'python2.7': 0.31; 'sep': 0.31; 'steven': 0.31; 'file': 0.32; 'url:python': 0.33; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'really': 0.36; '8bit%:80': 0.36; 'url:org': 0.36; 'should': 0.36; 'january': 0.37; 'two': 0.37; 'skip:o 20': 0.38; '8bit%:86': 0.38; 'hat': 0.38; 'bad': 0.39; 'skip:p 20': 0.39; 'skip:u 10': 0.60; 'more': 0.64; 'different': 0.65; 'details': 0.65; '8bit%:40': 0.68; '8bit%:50': 0.68; 'prompt': 0.68; '8bit%:100': 0.72; 'subject:this': 0.83; 'oscar': 0.84; '2013,': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=qFSN2ZRNfS4W5Vvir/jmn9s+eglY22gvICIQnmx8vac=; b=UB3mp19pBHD4p0TaR+qJeypqD6uskx7qfVvlPu4uaR9WdQjnwPOTY8EvXRecq5JNrZ kW6Fr3gKR3NVzXkV4Fd4H+VkOcJ1PShW/nA/OPb85sz/L/rBy1vosLsnph1J+kVIJ3+K jPD0XxP80rrU7YkOClt6u8Q8KYC7STAbLMFBBkFix7MuWvHU8TJcUceuSgDZO3863EZq sJMc0zaw3mc5Fu2u7QjD4FhBNXBnJT5e7q56XrXJkuC0GnxvffbPXvlttdQDYf9cSHso g/ptPwXm+h7be3XwBGDSSjkguXLKsLJ2LbXRIfRbwxa1kIO6SGY3kC3+0cDZ2cOHEtzV agpw== |
| X-Received | by 10.66.251.42 with SMTP id zh10mr21897246pac.84.1390684532941; Sat, 25 Jan 2014 13:15:32 -0800 (PST) |
| MIME-Version | 1.0 |
| In-Reply-To | <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> |
| References | <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> |
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
| Date | Sat, 25 Jan 2014 21:15:12 +0000 |
| Subject | Re: Trying to understand this moji-bake |
| To | "Steven D'Aprano" <steve+comp.lang.python@pearwood.info> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | Python List <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5981.1390684541.18130.python-list@python.org> (permalink) |
| Lines | 90 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1390684541 news.xs4all.nl 2932 [2001:888:2000:d::a6]:33374 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:64752 |
Show key headers only | View raw
On 25 January 2014 04:37, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
>
> But using Python 2.7, I get a really bad case of moji-bake:
>
> [steve@ando ~]$ python2.7 -c "print u'ñøλπйж'"
> ñøλÏйж
>
> However, interactively it works fine:
>
> [steve@ando ~]$ python2.7 -E
> Python 2.7.2 (default, May 18 2012, 18:25:10)
> [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> print u'ñøλπйж'
> ñøλπйж
>
> This occurs on at least two different machines, one using Centos and the
> other Debian.
Same for me. It's to do with using a u literal:
$ python2.7 -c "print('ñøλπйж')"
ñøλπйж
$ python2.7 -c "print(u'ñøλπйж')"
ñøλπйж
$ python2.7 -c "print(repr('ñøλπйж'))"
'\xc3\xb1\xc3\xb8\xce\xbb\xcf\x80\xd0\xb9\xd0\xb6'
$ python2.7 -c "print(repr(u'ñøλπйж'))"
u'\xc3\xb1\xc3\xb8\xce\xbb\xcf\x80\xd0\xb9\xd0\xb6'
$ python2.7
Python 2.7.5+ (default, Sep 19 2013, 13:49:51)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> b='\xc3\xb1\xc3\xb8\xce\xbb\xcf\x80\xd0\xb9\xd0\xb6'
>>> print(b)
ñøλπйж
>>> s=u'\xc3\xb1\xc3\xb8\xce\xbb\xcf\x80\xd0\xb9\xd0\xb6'
>>> print(s)
ñøλπйж
>>> print(s.encode('latin-1'))
ñøλπйж
>>> import sys
>>> sys.getdefaultencoding()
'ascii'
It works in the interactive prompt:
>>> s = 'ñøλπйж'
>>> print(s)
ñøλπйж
>>> s = u'ñøλπйж'
>>> print(s)
ñøλπйж
But the interactive prompt has an associated encoding:
>>> import sys
>>> sys.stdout.encoding
'UTF-8'
If I put it into a utf-8 file with no encoding declared I get a SyntaxError:
$ cat tmp.py
s = u'ñøλπйж'
print(s)
oscar@tonis-laptop:~$ python2.7 tmp.py
File "tmp.py", line 1
SyntaxError: Non-ASCII character '\xc3' in file tmp.py on line 1, but
no encoding declared; see http://www.python.org/peps/pep-0263.html for
details
If I add the encoding declaration it works:
oscar@tonis-laptop:~$ vim tmp.py
oscar@tonis-laptop:~$ cat tmp.py
# -*- coding: utf-8 -*-
s = u'ñøλπйж'
print(s)
oscar@tonis-laptop:~$ python2.7 tmp.py
ñøλπйж
oscar@tonis-laptop:~$
So I'd say that your original example should be a SyntaxError with
Python 2.7 but instead it implicitly uses latin-1.
Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Trying to understand this moji-bake Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-25 04:37 +0000
Re: Trying to understand this moji-bake Cameron Simpson <cs@zip.com.au> - 2014-01-25 16:08 +1100
Re: Trying to understand this moji-bake Chris Angelico <rosuav@gmail.com> - 2014-01-25 17:08 +1100
Re: Trying to understand this moji-bake Peter Pearson <ppearson@nowhere.invalid> - 2014-01-25 17:56 +0000
Re: Trying to understand this moji-bake Chris Angelico <rosuav@gmail.com> - 2014-01-26 06:13 +1100
Re: Trying to understand this moji-bake Terry Reedy <tjreedy@udel.edu> - 2014-01-25 22:31 -0500
Re: Trying to understand this moji-bake Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-26 02:04 +0000
Re: Trying to understand this moji-bake Chris Angelico <rosuav@gmail.com> - 2014-01-26 13:08 +1100
Re: Trying to understand this moji-bake Peter Otten <__peter__@web.de> - 2014-01-25 09:56 +0100
Re: Trying to understand this moji-bake wxjmfauth@gmail.com - 2014-01-25 01:24 -0800
Re: Trying to understand this moji-bake Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-01-25 21:15 +0000
csiph-web