Author steven.daprano
Recipients steven.daprano
Date 2009-01-14.11:18:47
SpamBayes Score 8.1094e-07
Marked as misclassified No
Message-id <1231931928.79.0.528374921948.issue4947@psf.upfronthosting.co.za>
In-reply-to
Content
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'))
啊
History
Date User Action Args
2009-01-14 11:18:48steven.dapranosetrecipients: + steven.daprano
2009-01-14 11:18:48steven.dapranosetmessageid: <1231931928.79.0.528374921948.issue4947@psf.upfronthosting.co.za>
2009-01-14 11:18:47steven.dapranolinkissue4947 messages
2009-01-14 11:18:47steven.dapranocreate