Message79849
Documentation for files states that when writing to a file, unicode
strings are converted to byte strings using the encoding specified by
file.encoding.
http://docs.python.org/library/stdtypes.html#file.encoding
sys.stdout is a file, but it does not behave as stated above:
>>> type(sys.stdout)
<type 'file'>
>>> sys.stdout.encoding
'UTF-8'
>>> u = u"\u554a"
>>> print u
啊
>>> sys.stdout.write(u)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u554a' in
position 0: ordinal not in range(128)
>>> sys.stdout.write(u.encode('utf-8'))
啊 |
|
Date |
User |
Action |
Args |
2009-01-14 11:18:48 | steven.daprano | set | recipients:
+ steven.daprano |
2009-01-14 11:18:48 | steven.daprano | set | messageid: <1231931928.79.0.528374921948.issue4947@psf.upfronthosting.co.za> |
2009-01-14 11:18:47 | steven.daprano | link | issue4947 messages |
2009-01-14 11:18:47 | steven.daprano | create | |
|