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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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.