Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'scripts': 0.03; 'explicitly': 0.05; 'subject:code': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'function,': 0.09; 'message-id:@stoneleaf.us': 0.09; 'subject:string': 0.09; '~ethan~': 0.09; '__future__': 0.16; 'filename:fname piece:signature': 0.16; 'finney': 0.16; 'literals': 0.16; 'subject: \n ': 0.16; 'subject:between': 0.16; 'those,': 0.16; 'too).': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'specify': 0.24; 'unicode': 0.24; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'needed.': 0.30; 'text': 0.33; 'up.': 0.33; 'ben': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'ensure': 0.60; 'skip:u 10': 0.60; 'received:173': 0.61; 'great': 0.65; 'skip:\xe2 10': 0.65; '8bit%:40': 0.68; 'believe,': 0.84 Date: Mon, 15 Dec 2014 09:23:08 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Portable code: __import__ demands different string types between 2 and 3 References: <85wq5tpe0g.fsf@benfinney.id.au> In-Reply-To: <85wq5tpe0g.fsf@benfinney.id.au> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="JaLms8Mj3bOc8WMBRV2Hc28RiuaE8vcNI" 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: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418664261 news.xs4all.nl 2835 [2001:888:2000:d::a6]:35527 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82564 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --JaLms8Mj3bOc8WMBRV2Hc28RiuaE8vcNI Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 12/14/2014 11:29 PM, Ben Finney wrote: >=20 > This entails, I believe, the admonition to ensure text literals are > Unicode by default:: >=20 > from __future__ import unicode_literals >=20 > and to specify bytes literals explicitly with =E2=80=98b'wibble'=E2=80=99= if needed. For some scripts this works great (I have some), and for some it does not= (I have some of those, too). > The =E2=80=98__import__=E2=80=99 built-in function, though, is tripping= up. One work-around I have used is: if isinstance(some_var, bytes): some_var =3D some_var.decode('ascii') # at this point some_var is unicode in both Pythons -- ~Ethan~ --JaLms8Mj3bOc8WMBRV2Hc28RiuaE8vcNI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBAgAGBQJUjxkbAAoJENZ7D1rrH75NwfgP/3n2lKX+fiCMqHjdiP1CDNzO ZrVdfiuoq1dpdF4PKcDmGoeeCyfQHFdXLlWpsnfRyb19AfQOX9VN3aEx5SPAbYAF pzAyqartH6kykdTk7xshAIB4Xyqsq6syPADVn8eSnqjdEFNx64yTo6LP1jXv+bco LLIEwB8qRi5bWL5C70+Qs4SQPXAJFQsHeL34BHcGrIny/LqGOmsARf+WK+C1wnFE nF8XVEc0k9R+GtAKqkbLFL2vMl/5D3vVsE5h5vOXhvyKFfxz+QsTjbmQ4Ce3cjz7 GQYhoRZ5Rqg1Ng5H43x7Eh6omjnrdkJ2ddgr7oy52+ytMri6peOPKTRkn34DPyMj h+BTQGltx4mGfzPgG2cGZZBmDifE7UlfBpjDm0dDMUfri+jNB1VfBofQIHNjrjt9 j6vISTc7YEmxd7RwSqIZ15p1anJDoSDkmuSJ1JwuHBX8LsSY1sJ49IVq7wZwtxC2 XYi96vTTzFjJi5Our9lkbEmzprrPoOCHRQSNHWGS+IB8Jx4aqpPQ/sZzxoskU/C0 a6lLyn6PZG2I69msBeWPI7J1Mw+Ac0LGR0oQj2ulVvDfNPxBWNtiwwXYSZOS07n3 IltmIX3zNrm/bt1eTXCkrfM7+N7MBsZRJ4IRZLQlOaPlSLEBycVpUlKp8gQv9spt HBJtmSX5fZpMGZu80mEQ =cDTF -----END PGP SIGNATURE----- --JaLms8Mj3bOc8WMBRV2Hc28RiuaE8vcNI--