Return-Path: 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; 'syntax': 0.04; 'say,': 0.05; 'subject:code': 0.07; "'...'": 0.09; 'bytes,': 0.09; 'latter': 0.09; 'prefix': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:string': 0.09; 'python': 0.11; 'suggest': 0.14; '__future__': 0.16; 'beatrice': 0.16; 'disapprove': 0.16; 'finney': 0.16; 'hall,': 0.16; 'literal.': 0.16; 'porting': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:between': 0.16; 'subject:import': 0.16; 'subject:skip:u 10': 0.16; 'unicode,': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; "shouldn't": 0.24; 'unicode': 0.24; 'code:': 0.26; 'header:X -Complaints-To:1': 0.27; 'point': 0.28; 'specifically': 0.29; 'dec': 0.30; 'statement': 0.30; 'code': 0.31; 'context.': 0.31; 'seemingly': 0.31; 'writes:': 0.31; 'compatible': 0.32; 'text': 0.33; 'url:python': 0.33; 'advice': 0.35; 'skip:u 20': 0.35; 'but': 0.35; 'add': 0.35; '14,': 0.36; 'doing': 0.36; 'url:org': 0.36; 'should': 0.36; 'so,': 0.37; 'ben': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'url:3': 0.61; "you're": 0.61; "you'll": 0.62; 'such': 0.63; 'benefit': 0.68; 'url:4': 0.69; 'subjectcharset:utf-8': 0.72; 'friends': 0.81; 'moot': 0.84; 'received:125': 0.84; 'subject:good': 0.84; 'subject::': 0.85 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Portable code: =?utf-8?Q?=E2=80=98from?= __future__ import =?utf-8?Q?unicode=5Fliterals=E2=80=99?= a good idea? (was: Portable code: __import__ demands different string types between 2 and 3) Date: Tue, 16 Dec 2014 11:42:04 +1100 References: <85wq5tpe0g.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:tR2DGRBX3JLkLZhj3S708+Sh3SM= 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418690560 news.xs4all.nl 2974 [2001:888:2000:d::a6]:35946 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:82567 Devin Jeanpierre writes: > On Sun, Dec 14, 2014 at 11:29 PM, Ben Finney wrote: > > from __future__ import unicode_literals > > Ordinarily, for 2.x/3.3+ code I would suggest not doing this -- > instead, b'...' for bytes, u'...' for unicode, and '...' for native > "string" type (bytes on 2.x, unicode on 3.x). This is the main benefit > of the u'...' syntax addition. That latter point would seemingly also apply to ‘from __future__ import unicode_literals’, so is moot in this context. As for the advice to avoid such a declaration, you're arguing against the official guide for porting Python 2 code to 2-and-3 compatible code: For text you should either use the from __future__ import unicode_literals statement or add a u prefix to the text literal. So, the declarative import is specifically recommended. You'll need to present a case for why I shouldn't follow that recommendation. -- \ “I disapprove of what you say, but I will defend to the death | `\ your right to say it.” —Evelyn Beatrice Hall, _The Friends of | _o__) Voltaire_, 1906 | Ben Finney