Portable code: ‘from __future__ import unicode_literals’ a good idea?

Ben Finney ben+python at benfinney.id.au
Mon Dec 15 21:31:50 EST 2014


Ned Batchelder <ned at nedbatchelder.com> writes:

> On 12/15/14 7:42 PM, Ben Finney wrote:
> > 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.
>
> What's wrong with this part of the recommendation?: "or add a u prefix
> to the text literal."

Who's saying there's anything wrong with that? Not I.

My question is, what's wrong with the first part such that Devin
recommends against it?

> Also, keep in mind, these recommendations are not infallible.

Yes, Devin clears up in a later message that the official guide provides
no advice for the case where an API needs ‘bytes’ in Python 2 but
Unicode in Python 3.

> Be flexible.  Do what works.

Good advice, but nothing different from what I'm already trying to do.

-- 
 \        “[R]ightful liberty is unobstructed action, according to our |
  `\        will, within limits drawn around us by the equal rights of |
_o__)                                 others.” —Thomas Jefferson, 1819 |
Ben Finney




More information about the Python-list mailing list