Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81076 > unrolled thread
| Started by | Francis Moreau <francis.moro@gmail.com> |
|---|---|
| First post | 2014-11-20 15:14 +0100 |
| Last post | 2014-11-20 15:14 +0100 |
| 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.
Re: python 2.7 and unicode (one more time) Francis Moreau <francis.moro@gmail.com> - 2014-11-20 15:14 +0100
| From | Francis Moreau <francis.moro@gmail.com> |
|---|---|
| Date | 2014-11-20 15:14 +0100 |
| Subject | Re: python 2.7 and unicode (one more time) |
| Message-ID | <mailman.16019.1416492865.18130.python-list@python.org> |
Hi,
On 11/20/2014 11:47 AM, Chris Angelico wrote:
> On Thu, Nov 20, 2014 at 8:40 PM, Francis Moreau <francis.moro@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.
Thanks for the "from __future__ import unicode_literals" trick, it makes
that switch much less intrusive.
However it seems that I will suddenly be trapped by all modules which
are not prepared to handle unicode. For example:
>>> from __future__ import unicode_literals
>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'fr_FR')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/locale.py", line 546, in setlocale
locale = normalize(_build_localename(locale))
File "/usr/lib64/python2.7/locale.py", line 453, in _build_localename
language, encoding = localetuple
ValueError: too many values to unpack
Is the locale module an exception and in that case I'll fix it by doing:
>>> locale.setlocale(locale.LC_ALL, b'fr_FR')
or is a (big) part of the modules in python 2.7 still not ready for
unicode and in that case I have to decide which prefix (u or b) I should
manually add ?
Thanks.
Back to top | Article view | comp.lang.python
csiph-web