Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81078

Re: python 2.7 and unicode (one more time)

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'encoding': 0.05; '21,': 0.07; 'float': 0.07; 'string': 0.09; '%s"': 0.09; 'ascii': 0.09; 'bytes,': 0.09; 'encode': 0.09; 'option,': 0.09; 'subject:2.7': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '12:59': 0.16; 'codec': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'literals': 0.16; 'n\xc3\xb6tig': 0.16; 'ordinal': 0.16; 'other,': 0.16; 'personally,': 0.16; 'subject:unicode': 0.16; 'surprising': 0.16; 'types,': 0.16; 'unicode.': 0.16; 'subject:python': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'thu,': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'byte': 0.24; 'string,': 0.24; 'unicode': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '"",': 0.31; 'int,': 0.31; 'file': 0.32; 'text': 0.33; '(most': 0.33; 'fri,': 0.33; 'subject:time': 0.33; 'sense': 0.34; "i'd": 0.34; 'subject: (': 0.35; "can't": 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'picking': 0.36; 'subject:one': 0.36; 'should': 0.36; 'two': 0.37; 'clear': 0.37; 'easily': 0.37; 'being': 0.38; 'nov': 0.38; 'rather': 0.38; 'recent': 0.39; 'skip:u 10': 0.60; 'back': 0.62; "you'll": 0.62; 'subject:more': 0.64; 'more': 0.64; '20,': 0.68; '2014,': 0.84; 'float,': 0.84; 'otten': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=RwMTX5mn/HqVE2vIU5iiPJOecjIGwq1X/ul+PKzSd7g=; b=Wz/LvbHIjAyh9F6ayeH/qACgwbj6xNhIWXKpXTs1VYvd/AVNHBvqF+UVpW8RoXTfDd 1nElFuM3kGMwbrNAR9p7fGTG84oqkMF23xOCoKpdmHPzu0HemgUdNbRRK9wTtSKOf/uw wbQWv6ob2EkY2s/2DQ6FL+chIgwQFjs/IQKkc1OXkzTAW/lx3OEgrktLDbZ6IoPicUfu 7symhXLFqzxuZPARt014M+D/otu7kUKFBh05MF/j3/cwuLjRUH/lmplh6M3v81rCpDN0 JfaqQB+v/bxzJdMqGfwO8mKjFrcyTtjNQgJjUfx+wNcYyZfnPEXhgU0y2Jd6K/v3RdWD 7DfA==
MIME-Version 1.0
X-Received by 10.42.142.201 with SMTP id t9mr1332700icu.60.1416495553171; Thu, 20 Nov 2014 06:59:13 -0800 (PST)
In-Reply-To <1416491999.209592.193345213.3A6FF9A4@webmail.messagingengine.com>
References <m4kcu8$ta8$1@ger.gmane.org> <m4kn66$ma3$1@ger.gmane.org> <1416491999.209592.193345213.3A6FF9A4@webmail.messagingengine.com>
Date Fri, 21 Nov 2014 01:59:13 +1100
Subject Re: python 2.7 and unicode (one more time)
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
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.16020.1416495561.18130.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416495561 news.xs4all.nl 2838 [2001:888:2000:d::a6]:32858
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81078

Show key headers only | View raw


On Fri, Nov 21, 2014 at 12:59 AM,  <random832@fastmail.us> wrote:
> On Thu, Nov 20, 2014, at 07:35, Peter Otten wrote:
>> >>> "%s nötig %s" % (u"üblich", u"ähnlich")
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4:
>> ordinal not in range(128)
>
> This is surprising to me - why is it trying to decode the format string,
> rather than encode the arguments?

Why should it encode to bytes? Makes much better sense to work in
Unicode. But mainly, it has to do one of them, and be predictable. If
you add a float and an int, you have to predictably get back one of
those two types, and since neither is a perfect superset of the other,
one just has to be picked. (And that's float, because it's more likely
to be the better option.) In this case, picking Unicode to meet on is
easily the better option, because you'll often have pure-ASCII string
literals as format strings, and Unicode data being interpolated into
it. So using an ASCII codec is far more likely to succeed if you
decode the format string than if you encode the data.

Personally, I'd much rather be very clear about what's text and what's
bytes, and not have any automatic encoding at all. That's why I use
Python 3.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: python 2.7 and unicode (one more time) Chris Angelico <rosuav@gmail.com> - 2014-11-21 01:59 +1100

csiph-web