Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82564
| 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 | <ethan@stoneleaf.us> |
| 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 <ethan@stoneleaf.us> |
| 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 <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.16985.1418664261.18130.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On 12/14/2014 11:29 PM, Ben Finney wrote:
>
> This entails, I believe, the admonition to ensure text literals are
> Unicode by default::
>
> from __future__ import unicode_literals
>
> and to specify bytes literals explicitly with ‘b'wibble'’ if needed.
For some scripts this works great (I have some), and for some it does not (I have some of those, too).
> The ‘__import__’ built-in function, though, is tripping up.
One work-around I have used is:
if isinstance(some_var, bytes):
some_var = some_var.decode('ascii')
# at this point some_var is unicode in both Pythons
--
~Ethan~
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Portable code: __import__ demands different string types between 2 and 3 Ethan Furman <ethan@stoneleaf.us> - 2014-12-15 09:23 -0800
csiph-web