Version upgrade blocked mentally

"Martin v. Löwis" martin at v.loewis.de
Sat Nov 29 18:33:01 EST 2008


>>> I have read in my copy of Programming Python that all strings will be
>>> Unicode and there will be a byte type.
>> Actually that change is scheduled for 3.0.
> 
> Yes, but it's available in 2.6 as well:
>    >>> from __future__ import unicode_literals
>    >>> type('')
>    <type 'unicode'>

That's different, though, from "all strings will be Unicode":

3.0:
py> print(chr(30000))
田
py> def 田():pass
...
py> type(田.__name__)
<class 'str'>

2.6
py> print(chr(30000))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: chr() arg not in range(256)
py> def 田():pass
  File "<stdin>", line 1
    def 田():pass
        ^
SyntaxError: invalid syntax

So: in 2.6, chr still generates byte strings, and names of functions,
classes, etc. are still byte strings. Byte strings continue to occur
in many more cases (e.g. when reading from a file opened in text mode).
In 3.0, *all* these strings become Unicode strings.

Regards,
Martin



More information about the Python-list mailing list