Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81065
| From | Francis Moreau <francis.moro@gmail.com> |
|---|---|
| Subject | python 2.7 and unicode (one more time) |
| Date | 2014-11-20 10:40 +0100 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16010.1416476438.18130.python-list@python.org> (permalink) |
Hello,
My application is using gettext module to do the translation
stuff. Translated messages are unicode on both python 2 and
3 (with python2.7 I had to explicitely asked for unicode).
A problem arises when formatting those messages before logging
them. For example:
log.debug("%s: %s" % (header, _("will return an unicode string")))
Indeed on python2.7, "%s: %s" is 'str' whereas _() returns
unicode.
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.
or is there a proper solution ?
Thanks.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
python 2.7 and unicode (one more time) Francis Moreau <francis.moro@gmail.com> - 2014-11-20 10:40 +0100 Re: python 2.7 and unicode (one more time) Simon Evans <musicalhacksaw@yahoo.co.uk> - 2014-12-02 14:40 -0800
csiph-web