[Python-3000] u'text' as an alias for 'text'?

Lennart Regebro regebro at gmail.com
Thu Mar 20 08:48:11 CET 2008


Hiya all, I've googled for this issue but I couldn't find it so I hope
this hasn't been beaten to death already.

I've been doing some compatibility tests with 3.0a3, 2.6a1 and 2.5, to
see exactly what breaks and how and if you can get around it,
basically to see if it is possible to write code that runs under both
2.6 and 3.0 without too much pain. It's looking rather encouraging,
most differences have easy workarounds. Some of them need try/except
clauses which could be collected in a small compatibility module
installable as an egg for those who want it.

There is one big problem though, and it's unicode. I'm happy to see
that 2.6 has the b'data' syntax as an alias for 'data', to make it
easier to port code from 2.6 to 3.0. But 3.0 doesn't support the
u''syntax, and that means that it gets very hard to use unicode in an
application and run it under 2.6 and 3.0. You can get around it with
this workaround:

    try:
        u = unicode
    except NameError:
        u = str
    text = u("This is unicode")

But this is still not perfect, as this means you only can have
ascii-texts in the unicode strings. That's OK for people like me that
use Zope, because we'll use i18n tools to localize texts anyway, but I
suspect it's not going to be OK for others. Also, it's ugly. :-)


I would really like to see u'text' support in Python 3.0, as an alias
for 'text'. If we can have that, it means that 90% of all code I have
written will just straight of in Python 3.0 (yeah, really), and most
of the remaining code can be fixed with conditional imports of the
renamed standard modules.

Admittedly, this is because I rarely use xrange or iterkeys. Also, I
rarely print, I use the logging module, and so on. But I don't think
that is so unusual, is it?


So, please allow u'' in Python 3.0! With that change, my
porting/compatibility worried would be gone, and  you would be able to
choose between the three porting strategies dependningon how your code
base and user base looks: 1. Clean break. 2. Syncing with 2to3, 3.
Supporting both 2.6 and 3.0.

-- 
Lennart Regebro: Zope and Plone consulting.
http://www.colliberty.com/
+33 661 58 14 64


More information about the Python-3000 mailing list