Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81065

python 2.7 and unicode (one more time)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!weretis.net!feeder1.news.weretis.net!news.roellig-ltd.de!open-news-network.org!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'string': 0.09; '%s"': 0.09; 'explicitely': 0.09; 'formatting': 0.09; 'gettext': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:2.7': 0.09; 'python': 0.11; 'translation': 0.12; 'logger': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'stuff.': 0.16; 'subject:unicode': 0.16; 'unicode.': 0.16; 'subject:python': 0.16; 'module': 0.19; 'properly': 0.19; 'translated': 0.19; 'thanks.': 0.20; 'header:User-Agent:1': 0.23; 'unicode': 0.24; 'question': 0.24; 'logging': 0.26; 'header:X-Complaints-To:1': 0.27; 'fixed': 0.29; 'generally': 0.29; 'asked': 0.31; 'code': 0.31; 'python2.7': 0.31; 'subject:time': 0.33; 'problem': 0.35; 'subject: (': 0.35; 'there': 0.35; 'subject:one': 0.36; 'should': 0.36; 'application': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'simple': 0.61; 'subject:more': 0.64; 'more': 0.64; 'whereas': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Francis Moreau <francis.moro@gmail.com>
Subject python 2.7 and unicode (one more time)
Date Thu, 20 Nov 2014 10:40:24 +0100
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host gem13-1-78-228-1-221.fbx.proxad.net
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16010.1416476438.18130.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416476438 news.xs4all.nl 2883 [2001:888:2000:d::a6]:59333
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81065

Show key headers only | View raw


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


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