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


Groups > comp.lang.python > #81103

Re: python 2.7 and unicode (one more time)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '21,': 0.07; 'string': 0.09; '%s"': 0.09; 'encode': 0.09; 'propagate': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:2.7': 0.09; '12:59': 0.16; 'codec': 0.16; 'n\xc3\xb6tig': 0.16; 'ordinal': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:unicode': 0.16; 'surprising': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'result.': 0.19; 'thu,': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'byte': 0.24; 'bytes': 0.24; 'string,': 0.24; 'unicode': 0.24; 'developers': 0.25; 'header:X -Complaints-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; 'characters': 0.30; 'newer': 0.30; 'work.': 0.31; 'code': 0.31; '"",': 0.31; 'file': 0.32; 'probably': 0.32; '(most': 0.33; 'cases': 0.33; 'fri,': 0.33; 'guess': 0.33; 'subject:time': 0.33; 'subject: (': 0.35; "can't": 0.35; 'subject:one': 0.36; 'method': 0.36; 'should': 0.36; 'expected': 0.38; 'nov': 0.38; 'to:addr :python-list': 0.38; 'rather': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'introduced': 0.61; 'subject:more': 0.64; 'more': 0.64; 'due': 0.66; '20,': 0.68; '2014,': 0.84; 'otten': 0.84; 'unaware': 0.84; 'attitude': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: python 2.7 and unicode (one more time)
Date Thu, 20 Nov 2014 19:26:53 +0100
Organization None
References <m4kcu8$ta8$1@ger.gmane.org> <m4kn66$ma3$1@ger.gmane.org> <1416491999.209592.193345213.3A6FF9A4@webmail.messagingengine.com> <CAPTjJmr5NWMFCfU8jaNd2g2f9cQ1y+zO3qT7yVcC_m9vKXN6fw@mail.gmail.com> <1416505379.268157.193439717.66E319D4@webmail.messagingengine.com>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Gmane-NNTP-Posting-Host p57bdab72.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
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.16040.1416508028.18130.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416508028 news.xs4all.nl 2854 [2001:888:2000:d::a6]:60097
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81103

Show key headers only | View raw


random832@fastmail.us wrote:

> On Thu, Nov 20, 2014, at 09:59, Chris Angelico wrote:
>> 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?
> 
> Because a bytes format string suggests a bytes result. Why does unicode
> always "win", rather than the type of the format string always winning?

My guess is that when unicode was introduced the decision to propagate str 
to unicode in some cases was made because the developers expected that more 
old code that was unaware of unicode would continue to work. 

The old methods __mod__(), replace(), and join() that conceptually deal with 
strings propate while those that deal with characters -- center(), 
r/ljust(), translate() -- dont.

The newer format() method doesn't propagate which is probably due to a 
change in attitude rather than an oversight.

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


Thread

Re: python 2.7 and unicode (one more time) Peter Otten <__peter__@web.de> - 2014-11-20 19:26 +0100

csiph-web