Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!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; 'encoding': 0.05; 'explicit': 0.07; 'suddenly': 0.07; 'string': 0.09; '%s"': 0.09; 'locale': 0.09; 'prefix': 0.09; 'strings.': 0.09; 'subject:2.7': 0.09; 'valueerror:': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'language,': 0.12; '2.7': 0.14; '"from': 0.16; '8:40': 0.16; '__future__': 0.16; 'doing:': 0.16; 'literals': 0.16; 'logger': 0.16; 'subject:unicode': 0.16; 'unicode.': 0.16; 'unpack': 0.16; 'subject:python': 0.16; 'exception': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'module': 0.19; 'basically': 0.19; 'properly': 0.19; 'thu,': 0.19; 'thanks.': 0.20; 'seems': 0.21; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'byte': 0.24; 'skip:l 30': 0.24; 'unicode': 0.24; 'decide': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'skip:" 30': 0.26; 'switch': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'fixed': 0.29; 'chris': 0.29; 'am,': 0.29; 'generally': 0.29; 'code': 0.31; '"",': 0.31; 'file': 0.32; '(most': 0.33; 'subject:time': 0.33; 'skip:_ 10': 0.34; 'subject: (': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'subject:one': 0.36; 'thanks': 0.36; "i'll": 0.36; 'hi,': 0.36; 'should': 0.36; 'too': 0.37; 'represent': 0.38; 'message-id:@gmail.com': 0.38; 'nov': 0.38; 'handle': 0.38; 'pm,': 0.38; 'rather': 0.38; 'recent': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'manually': 0.60; 'skip:n 30': 0.60; 'simple': 0.61; "you're": 0.61; 'subject:more': 0.64; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'charset:windows-1252': 0.65; '20,': 0.68; 'trick,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=R6NxHVDOYR/OCIBWbzcR2F9HaTtQRnXeNJunUzJ9nrE=; b=0ZG9XoGrvlqzpJhC62i9uIPvn89uCdPSk1KuPKn3sUAogmV0tXA6J4E/+7VEHgQC80 4uVKfQg3maWHXLxU8Wji7xO92crIY9I95yAJ1LElBEYHv2INZRFedi6Yj1g4oC+ytlGw 4sgLR4qfI05Iu8N1ovsm2h/EJKbC/Ope4PHF8uI7KZzr3yp96Llwb7mtJUoQMiX41VSG h+hkqHpGbZj7hgAwj0ElU8tINS5Z/WTfw8FBhuzgk57oWVVUUxl0dNqELN+wbH1Yw7ck kkyrgNzJ+tB1mjtc2s9pMJPh8TbtoEXzrHz84BV+ArxyL28w5xFz/+8clKYbEqClo1+3 K13Q== X-Received: by 10.194.223.9 with SMTP id qq9mr47457406wjc.36.1416492858066; Thu, 20 Nov 2014 06:14:18 -0800 (PST) Date: Thu, 20 Nov 2014 15:14:16 +0100 From: Francis Moreau User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Chris Angelico Subject: Re: python 2.7 and unicode (one more time) References: In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Cc: "python-list@python.org" 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: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416492865 news.xs4all.nl 2848 [2001:888:2000:d::a6]:53701 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81076 Hi, On 11/20/2014 11:47 AM, Chris Angelico wrote: > On Thu, Nov 20, 2014 at 8:40 PM, Francis Moreau 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 "", line 1, in 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.