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.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com