Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'anyway.': 0.05; 'encoding': 0.05; 'encoded': 0.07; 'string': 0.09; 'ascii': 0.09; 'subject:2.7': 0.09; '%s,': 0.16; 'blindly': 0.16; 'failure.': 0.16; 'quoted': 0.16; 'str,': 0.16; 'subject:unicode': 0.16; 'unicode,': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'error': 0.23; 'unicode': 0.24; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; '(although': 0.31; 'object.': 0.31; 'safely': 0.31; 'subject:time': 0.33; 'subject: (': 0.35; "can't": 0.35; 'received:google.com': 0.35; 'subject:one': 0.36; 'nov': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'ian': 0.60; "you'll": 0.62; 'happen': 0.63; 'subject:more': 0.64; '20,': 0.68; 'silent': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=QktoU9fi39tkl8Sm4q/UaIZ6N0wu8x/fgftvq31rMnU=; b=e37bOu+CoJhQhBnfi9LQItU0l8z+gDt4ykFikE/LBYheauAzTQj8S5oopagXf9+pQA VrBQCQGLAgB5HRTTDCPjXniAWThENKV+/umlz3YfGzPhlyiBobK67OT+DJ+W5zSxFuqJ N9esJSJ8UwwLPspRJz9N53BIZlFKVovwbV0FrKnDdNHvkXOgnAx1Q3Pt9gu2NqTxyl+2 bpY7jCFCVvFRjot6LXnrUGqYM9YPyH6pSXYD9Gnwj0JM/AqqSto/xpwb7LwEqmWlJOv1 NQFAtQAxB0R5SQYpQeCDDEuKVvPFlVHpRq5FWPkdkAEXW8zmEWZqdEQUdVKHRJtEAGQJ GHDA== X-Received: by 10.66.191.135 with SMTP id gy7mr58249207pac.95.1416507015592; Thu, 20 Nov 2014 10:10:15 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <1416491999.209592.193345213.3A6FF9A4@webmail.messagingengine.com> <1416505379.268157.193439717.66E319D4@webmail.messagingengine.com> From: Ian Kelly Date: Thu, 20 Nov 2014 11:09:35 -0700 Subject: Re: python 2.7 and unicode (one more time) To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416507018 news.xs4all.nl 2935 [2001:888:2000:d::a6]:55880 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81102 On Thu, Nov 20, 2014 at 11:06 AM, Ian Kelly wrote: > On Thu, Nov 20, 2014 at 10:42 AM, wrote: >> and it means you can't safely >> blindly use %s with an unknown object. > > You can't safely do this anyway. Whether it's %s with a str and a > unicode, or %s with a unicode and a str, *something* is going to have > to be implicitly encoded or decoded, and if ascii doesn't happen to be > the correct encoding then the result will be either an error or a > silent failure. Also note that if you use %r instead of %s, you'll get the result you want (although the unicode string will be quoted rather than encoded).