Portable code: ‘from __future__ import unicode_literals’ a good idea?
Ned Batchelder
ned at nedbatchelder.com
Mon Dec 15 20:19:54 EST 2014
More information about the Python-list mailing list
Mon Dec 15 20:19:54 EST 2014
- Previous message (by thread): Re: Portable code: ‘from __future__ import unicode_literals’ a good idea? (was: Portable code: __import__ demands different string types between 2 and 3)
- Next message (by thread): Portable code: ‘from __future__ import unicode_literals’ a good idea?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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." Also, keep in mind, these recommendations are not infallible. They are sometimes written before there's been broad experience with the solution. Your use of __import__ puts you in a tiny minority of programs, so the recommendation that's good for 99% of code may not work for you. Be flexible. Do what works. -- Ned Batchelder, http://nedbatchelder.com
- Previous message (by thread): Re: Portable code: ‘from __future__ import unicode_literals’ a good idea? (was: Portable code: __import__ demands different string types between 2 and 3)
- Next message (by thread): Portable code: ‘from __future__ import unicode_literals’ a good idea?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list