Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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; 'syntax': 0.03; 'string.': 0.04; 'true)': 0.07; 'versions.': 0.07; 'python': 0.09; '__future__': 0.09; 'assumed': 0.09; "b''": 0.09; 'portable': 0.09; 'porting': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '3.2,': 0.16; 'eckhardt': 0.16; 'literal,': 0.16; 'literal.': 0.16; 'literals': 0.16; 'nudge': 0.16; 'portably': 0.16; 'rationale': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:unicode': 0.16; 'string': 0.17; 'wrote:': 0.17; 'byte': 0.17; 'unicode': 0.17; 'import': 0.21; 'error.': 0.21; 'feature': 0.24; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; 'wonder': 0.27; 'header:X-Complaints-To:1': 0.28; 'strings,': 0.29; "i'm": 0.29; 'code': 0.31; 'could': 0.32; 'to:addr:python- list': 0.33; 'something': 0.35; 'received:org': 0.36; 'drop': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'little': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'skip:u 10': 0.60; 'remove': 0.61; 'is.': 0.62; 'between': 0.63; 'surprise': 0.65 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Serhiy Storchaka Subject: Re: portable unicode literals Date: Mon, 15 Oct 2012 20:11:45 +0300 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 37.115.213.25 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120912 Thunderbird/15.0.1 In-Reply-To: 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350321135 news.xs4all.nl 6977 [2001:888:2000:d::a6]:54235 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31322 On 15.10.12 16:05, Ulrich Eckhardt wrote: > I need a little nudge in the right direction, as I'm misunderstanding > something concerning string literals in Python 2 and 3. In Python 2.7, > b'' and '' are byte strings, while u'' is a unicode literal. In Python > 3.2, b'' is a byte string and '' is a unicode literal, while u'' is a > syntax error. > > This actually came as a surprise to me, I assumed that using b'' I could > portably create a byte string (which is true) and using u'' I could > portably create a unicode string (which is not true). This feature would > help porting code between both versions. While this is a state I can > live with, I wonder what the rationale for this is. from __future__ import unicode_literals And now you can portable use b'' for a byte string and '' for a unicode string. When you will drop Python 2 support then just remove import from __future__.