Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; '21,': 0.07; 'string': 0.09; '%s"': 0.09; 'converted': 0.09; 'encode': 0.09; "people's": 0.09; 'received:internal': 0.09; 'subject:2.7': 0.09; 'yeah,': 0.09; '(both': 0.16; '12:59': 0.16; 'blindly': 0.16; 'codec': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'n\xc3\xb6tig': 0.16; 'operator.': 0.16; 'ordinal': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:messagingengine.com': 0.16; 'string)': 0.16; 'subject:unicode': 0.16; 'surprising': 0.16; 'unicode.': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'result.': 0.19; 'thu,': 0.19; '>>>': 0.22; 'adds': 0.24; 'byte': 0.24; 'bytes': 0.24; 'string,': 0.24; 'unicode': 0.24; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'am,': 0.29; '(which': 0.31; '"",': 0.31; 'object.': 0.31; 'safely': 0.31; 'file': 0.32; '(most': 0.33; 'fri,': 0.33; 'subject:time': 0.33; 'sense': 0.34; 'received:66': 0.35; 'subject: (': 0.35; "can't": 0.35; 'but': 0.35; 'subject:one': 0.36; 'should': 0.36; 'received:10': 0.37; 'nov': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'from:no real name:2**0': 0.61; 'header:Message-Id:1': 0.63; 'subject:more': 0.64; '20,': 0.68; 'acts': 0.74; 'special': 0.74; '2014,': 0.84; 'otten': 0.84; 'cognitive': 0.91 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.us; h= message-id:x-sasl-enc:from:to:mime-version :content-transfer-encoding:content-type:subject:date:in-reply-to :references; s=mesmtp; bh=TJapTmzF6I3PzpUB4uYfLzMbWT0=; b=N0BO61 qAXNgtjHxVjEb8t1ZzDeEaTOnKheDiuU9ZUECjtvsqhs+oWRprdCxgme1aAHB08u jG8OGeGQ8xFCXnhftVzxCJ+ipoLnDEh/6HGFr1KCZgU2BW+fTX4q/X+CLUvEGnxW 01ekpOc4kOCk0hKZC8Tk5L9AhYG3nn84T6lZY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:x-sasl-enc:from:to :mime-version:content-transfer-encoding:content-type:subject :date:in-reply-to:references; s=smtpout; bh=TJapTmzF6I3PzpUB4uYf LzMbWT0=; b=d4HjVpkd+rA7l6wv5r8jtKNifGP9K/KhEAyXL/JYxBc1647kzeEc xMhHLEtrvjWlJPM93M7fGFsMED8qQhyyW2fgn/6s6xE7wUS++Jk7k1mjawrAgnIX n0kUD+GwlaPBFWv0t9eFsyMXdofhejuO7Zh49KwowBVxvMcFKG2o1r8= X-Sasl-Enc: 0oPwgbxRklUeh5kSc7/uWu7MyCtJa79eOAx7QqjSLgJd 1416505379 From: random832@fastmail.us To: python-list@python.org MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-Mailer: MessagingEngine.com Webmail Interface - ajax-a419c8a0 Subject: Re: python 2.7 and unicode (one more time) Date: Thu, 20 Nov 2014 12:42:59 -0500 In-Reply-To: References: <1416491999.209592.193345213.3A6FF9A4@webmail.messagingengine.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416505382 news.xs4all.nl 2955 [2001:888:2000:d::a6]:43548 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81098 On Thu, Nov 20, 2014, at 09:59, Chris Angelico wrote: > On Fri, Nov 21, 2014 at 12:59 AM, wrote: > > On Thu, Nov 20, 2014, at 07:35, Peter Otten wrote: > >> >>> "%s n=C3=B6tig %s" % (u"=C3=BCblich", u"=C3=A4hnlich") > >> Traceback (most recent call last): > >> File "", line 1, in > >> 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? >=20 > 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? > Makes much better sense to work in > Unicode. But mainly, it has to do one of them, and be predictable. Yeah, but string % is not a symmetrical operator. People's mental model of it is likely to be that it acts like format (which does use the type of the format string) or C sprintf/wsprintf (both of which use the same type for the format string and result). And literally every other type is converted to the type of the format string when used with %s - having unicode be special adds cognitive load, and it means you can't safely blindly use %s with an unknown object.