Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82564
| Date | 2014-12-15 09:23 -0800 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: Portable code: __import__ demands different string types between 2 and 3 |
| References | <85wq5tpe0g.fsf@benfinney.id.au> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16985.1418664261.18130.python-list@python.org> (permalink) |
[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