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


Groups > comp.lang.python > #82564 > unrolled thread

Re: Portable code: __import__ demands different string types between 2 and 3

Started byEthan Furman <ethan@stoneleaf.us>
First post2014-12-15 09:23 -0800
Last post2014-12-15 09:23 -0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Portable code: __import__ demands different string types between 2 and 3 Ethan Furman <ethan@stoneleaf.us> - 2014-12-15 09:23 -0800

#82564 — Re: Portable code: __import__ demands different string types between 2 and 3

FromEthan Furman <ethan@stoneleaf.us>
Date2014-12-15 09:23 -0800
SubjectRe: Portable code: __import__ demands different string types between 2 and 3
Message-ID<mailman.16985.1418664261.18130.python-list@python.org>

[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~

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web