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


Groups > comp.lang.python > #81069

Re: python 2.7 and unicode (one more time)

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'explicit': 0.07; 'string': 0.09; '%s"': 0.09; 'strings.': 0.09; 'subject:2.7': 0.09; 'cc:addr :python-list': 0.11; '"from': 0.16; '8:40': 0.16; '__future__': 0.16; 'behave': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'literals': 0.16; 'logger': 0.16; 'subject:unicode': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'basically': 0.19; 'properly': 0.19; 'thu,': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'byte': 0.24; 'unicode': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'fixed': 0.29; 'generally': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'subject:time': 0.33; 'subject: (': 0.35; 'received:google.com': 0.35; 'subject:one': 0.36; 'should': 0.36; 'represent': 0.38; 'nov': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'simple': 0.61; "you're": 0.61; 'subject:more': 0.64; 'more': 0.64; '20,': 0.68; 'bare': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=ScDuEeugSOCnyp5FxwLhIxF3tFbWYxlPlcpuuYFUBVQ=; b=ZZOysTm87ABBS26yhCwjWPg2v/RtvCokCskg3/jyxb7EYf/0YnqyWDAjraGMej3DEO EV8xjuXlCrcF1AJ9n0m8L/faNkYmDL3REH8Zx7UKv/tt+OaqTcwe0+PWAraoqlDBwfOR MNbIazSbp5So10kDVn77pMEfHJ1tAIh7x5T/vRbuWbtYCzmFn9KhEUtg4E17FSoDaLKz DS/j3oQ/CXzvkHFQieT96ZP9fMHoQVNjILCcyZ6g9eE1HrdozcUAI1ddp2BYgT2sPjFy lwPW2t/XO5uZOFeL0xAHT45kkv5LYkHKSv478CdX/3CHOkLidEWGGVxOs7dCakS/Kju5 8zeA==
MIME-Version 1.0
X-Received by 10.107.134.39 with SMTP id i39mr428126iod.53.1416480442003; Thu, 20 Nov 2014 02:47:22 -0800 (PST)
In-Reply-To <m4kcu8$ta8$1@ger.gmane.org>
References <m4kcu8$ta8$1@ger.gmane.org>
Date Thu, 20 Nov 2014 21:47:21 +1100
Subject Re: python 2.7 and unicode (one more time)
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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.16013.1416480450.18130.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416480450 news.xs4all.nl 2868 [2001:888:2000:d::a6]:49038
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81069

Show key headers only | View raw


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.

This will also make your Py2 code behave more like the way your Py3
code does (as bare string literals are always Unicode strings in Py3).

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: python 2.7 and unicode (one more time) Chris Angelico <rosuav@gmail.com> - 2014-11-20 21:47 +1100

csiph-web