[Python-Dev] readd u'' literal support in 3.3?

Barry Warsaw barry at python.org
Fri Dec 9 16:11:23 CET 2011

On Dec 09, 2011, at 03:18 PM, Lennart Regebro wrote:

>On Fri, Dec 9, 2011 at 04:34, Barry Warsaw <barry at python.org> wrote:
>> Sorry, I don't understand this.  What does it mean to be "str in both
>> versions"?  And why would you want that?
>It means that it's a str, that is a string of bytes, in Python 2, and
>a str, that is a string of Unicode characters, in Python 3. There are
>cases where you want this, for example not all libraries will accept
>both str and Unicode under Python 2.

As Chris points out, this seems to be a use case tied to WSGI and PEP 3333.  I
guess it's an unfortunate choice for so recent a PEP, but maybe there was no
way to do better.  Still, it seems the "native string" discussion is an
indication that the PEP is introducing a binary vs. text ambiguity when
switching Python versions.  My previous "you're screwed" comment comes back to
mind. ;)

>> As for "Unicode in Python 2 and str in Python 3", unadorned strings with the
>> future import in Python >= 2.6 does that just fine.
>Yes, but the future import will change this for *all* strings, making
>it impossible to have a string that is a "str" in both Python 2 and
>Python 3. For that reason, the future import is not enough as a
>solution (and I suspect, one major reason why I haven't actually seen
>any one using it).

It can certainly be useful in many contexts outside of WSGI.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20111209/d8662610/attachment.pgp>

More information about the Python-Dev mailing list