python 2.7 and unicode (one more time)

Chris Angelico rosuav at gmail.com
Thu Nov 20 11:47:21 CET 2014


On Thu, Nov 20, 2014 at 8:40 PM, Francis Moreau <francis.moro at gmail.com> wrote:
> My question is: how should this be fixed properly ?
>
> A simple solution would be to force all strings passed to the
> logger to be unicode:
>
>   log.debug(u"%s: %s" % ...)
>
> and more generally force all string in my code to be unicode by
> using the 'u' prefix.

Yep. And then you may want to consider "from __future__ import
unicode_literals", which will make string literals represent Unicode
strings rather than byte strings. Basically the same as you're saying,
only without the explicit u prefixes.

This will also make your Py2 code behave more like the way your Py3
code does (as bare string literals are always Unicode strings in Py3).

ChrisA



More information about the Python-list mailing list