[Python-3000] Python 3.0 Porting Strategies

Christian Heimes lists at cheimes.de
Thu Mar 27 09:45:26 CET 2008


Charles Merriam schrieb:
> On Wed, Mar 26, 2008 at 9:33 PM, Talin <talin at acm.org> wrote:
> ....
>>  For new code, however, there is an alternative strategy that doesn't
>>  involve 2to3 at all, which is to write code in the "greatest common
>>  subset" of 2.6 and 3.0.
>>
>>  As Lennart Regbro pointed out earlier, this common subset is actually
>>  quite large (larger than Guido originally intended, I think), and you
>>  can write some fairly substantial applications in it.
> 
> Ok, I'll bite.  How can I write the greatest common denominator of this code:
> 
> print "Hello World!"  # yes, that needs to be Unicode.


>>> from __future__ import unicode_literals
>>> print "Hello World!" # this is unicode

>>> from __future__ import print_function
>>> print("Hello World!")

>>> ""
u''
>>> type("") is unicode
True
>>> type("") is str
False
>>> type(b"") is bytes
True
>>> type(b"") is str
True
>>> type(u"") is unicode
True

Christian


More information about the Python-3000 mailing list