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

Serhiy Storchaka storchaka at gmail.com
Wed Dec 14 00:16:34 CET 2011


14.12.11 00:38, Nick Coghlan написав(ла):
> String translation is also an open question. For some codebases, you
> want both u"" and "" to translate to a Unicode "" (either in Py3k or
> via the future import), but if a code base deals with WSGI-style
> native strings (by means of u"" for text, "" for native, b"" for
> binary), then the more appropriate translation is to use the future
> import and map them to "", str("") and b"" respectively.

There are other place for native strings -- sys.argv.

if sys.argv[1] == str('-'):
     f = sys.stdin
else:
     f = open(sys.argv[1], 'r')

Yet another pitfall -- sys.stdin is bytes stream in 2.x and text stream 
in 3.x. For reading binary data:

if sys.argv[1] == str('-'):
     if sys.version_info[0] >= 3:
         f = sys.stdin.buffer.raw
     else:
         f = sys.stdin
else:
     f = open(sys.argv[1], 'r')

Reading text data is even more complicated in Python 2.x.



More information about the Python-Dev mailing list