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


Groups > comp.lang.python > #31299

Re: portable unicode literals

Date 2012-10-15 09:32 -0400
From Dave Angel <d@davea.name>
Subject Re: portable unicode literals
References <t8etk9-5h9.ln1@satorlaser.homedns.org>
Newsgroups comp.lang.python
Message-ID <mailman.2202.1350307975.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 10/15/2012 09:05 AM, Ulrich Eckhardt wrote:
> Hi!
>
> 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.
>
> !puzzled thanks
>
> Uli

Python 3.3 added that syntax, for easier porting.  You can now use
u"xyz" for a unicode string in both 2.x and 3.3

-- 

DaveA

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


Thread

portable unicode literals Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-15 15:05 +0200
  Re: portable unicode literals Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-15 13:26 +0000
  Re: portable unicode literals Dave Angel <d@davea.name> - 2012-10-15 09:32 -0400
  Re: portable unicode literals Alex Strickland <sscc@mweb.co.za> - 2012-10-15 15:41 +0200
    Re: portable unicode literals Duncan Booth <duncan.booth@invalid.invalid> - 2012-10-16 08:44 +0000
  Re: portable unicode literals Serhiy Storchaka <storchaka@gmail.com> - 2012-10-15 20:11 +0300

csiph-web