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


Groups > comp.lang.python > #82568

Re: Portable code: ‘from __future__ import unicode_literals’ a good idea? (was: Portable code: __import__ demands different string types between 2 and 3)

Path csiph.com!usenet.pasdenom.info!news.franciliens.net!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <jeanpierreda@gmail.com>
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; 'subject:code': 0.07; "'...'": 0.09; 'advice.': 0.09; 'bytes,': 0.09; 'latter': 0.09; 'prefix': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'suggest': 0.14; 'mostly': 0.14; '"..."': 0.16; '__future__': 0.16; 'finney': 0.16; 'identifiers': 0.16; 'literal.': 0.16; 'literals,': 0.16; 'porting': 0.16; 'subject:between': 0.16; 'subject:import': 0.16; 'subject:skip:u 10': 0.16; 'unicode,': 0.16; 'applies': 0.16; 'so.': 0.16; 'wrote:': 0.18; 'import': 0.22; 'saying': 0.22; 'cc:addr:python.org': 0.22; '2.x': 0.24; 'bytes': 0.24; "shouldn't": 0.24; 'string,': 0.24; 'text,': 0.24; 'unicode': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; '15,': 0.26; 'pass': 0.26; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'specifically': 0.29; 'dec': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'context.': 0.31; 'doc': 0.31; 'keys': 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; 'good.': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; '14,': 0.36; 'doing': 0.36; 'url:org': 0.36; 'should': 0.36; 'so,': 0.37; 'represent': 0.38; 'ben': 0.38; 'pm,': 0.38; 'that,': 0.38; 'either': 0.39; 'skip:u 10': 0.60; 'solve': 0.60; 'url:3': 0.61; "you're": 0.61; "you'll": 0.62; 'kind': 0.63; 'such': 0.63; 'benefit': 0.68; 'url:4': 0.69; 'subjectcharset:utf-8': 0.72; 'moot': 0.84; 'subject:good': 0.84
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=r7o0oLJduc7xaFd+yiTyzbarkXb4nRChfg0IWegsAFE=; b=TU60sfzk1IIm81m8YuHrw+zfetxSrKOFUCRJ11PRFIh+TDwNu4wP2g8j27KN4x2GSs P+RQDKg+2CgUBJQdLLKhNklaz6XyxetkpsufKULOqK0uE2bxtfSwBuSFBhYpcNHuNR1y Th14alEXCPhSrkhVvBWVnUeAqPue1ig6bqJBDWiLIQ8vJO9uXDksJWOkvPjTIU5n0st3 5qEtFfsuv2S4QciePwVcUZGy0i2k5od1ge/t0S9eGgZ9AmJwXdpBJ238jhHLNgy5motY hs55j383wl6O4ejAWQUaL6GJkKaXH4E3DehKqPDBarRHS0XUw5CZjcGGH6U6cSPzJXG/ aVVA==
X-Received by 10.224.103.74 with SMTP id j10mr61799148qao.101.1418691842116; Mon, 15 Dec 2014 17:04:02 -0800 (PST)
MIME-Version 1.0
In-Reply-To <85oar4pgrn.fsf_-_@benfinney.id.au>
References <85wq5tpe0g.fsf@benfinney.id.au> <CABicbJKZ9XhhXAwQZrHrb8HUa-4QoKf5jT96msNxeuoDbMzVSg@mail.gmail.com> <85oar4pgrn.fsf_-_@benfinney.id.au>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date Mon, 15 Dec 2014 17:03:21 -0800
Subject Re: Portable code: ‘from __future__ import unicode_literals’ a good idea? (was: Portable code: __import__ demands different string types between 2 and 3)
To Ben Finney <ben+python@benfinney.id.au>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc "comp.lang.python" <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.16989.1418691844.18130.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1418691844 news.xs4all.nl 2951 [2001:888:2000:d::a6]:45534
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:82568

Show key headers only | View raw


On Mon, Dec 15, 2014 at 4:42 PM, Ben Finney <ben+python@benfinney.id.au> wrote:
> Devin Jeanpierre <jeanpierreda@gmail.com> writes:
>
>> On Sun, Dec 14, 2014 at 11:29 PM, Ben Finney <ben+python@benfinney.id.au> 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.
>
>     <URL:https://docs.python.org/3.4/howto/pyporting.html#text-versus-binary-data>
>
> So, the declarative import is specifically recommended. You'll need to
> present a case for why I shouldn't follow that recommendation.

All the doc is saying there is to use unicode for text, in a way that
works in both 2.x and 3.x. I am saying that the unicode_literals
import is not necessarily the best way to do so.

Python has three categories of strings: things that should be bytes in
2.x and 3.x, things that should be unicode in 2.x and 3.x, and things
that should be bytes on 2.x and unicode on 3.x. The last category
applies mostly to identifiers -- the strings you pass to functions
like getattr or __import__, and the strings that are valid keys in
**kwargs, and so on. You need a way to represent the last kind of
string, whether it's unadorned "..." literals, or function calls like
identifier_string("..."). If you can solve that, you are good. The
official porting guide offers no advice.

-- Devin

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


Thread

Re: Portable code: ‘from __future__ import unicode_literals’ a good idea? (was: Portable code: __import__ demands different string types between 2 and 3) Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-12-15 17:03 -0800

csiph-web