This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vinay.sajip
Recipients methane, vinay.sajip
Date 2009-09-25.15:10:38
SpamBayes Score 0.00039324767
Marked as misclassified No
Message-id <1253891441.05.0.42390735918.issue6991@psf.upfronthosting.co.za>
In-reply-to
Content
There seems to be a problem with your foo.py. In it, you are writing a
byte-string to a stream returned from codecs.open. I don't think this is
correct: you should be writing a Unicode string to that stream, which
will convert to bytes using the stream's encoding, and write those bytes
to file. The following snippet illustrates:

>>> import codecs
>>> f = codecs.open('foo.txt', 'w', encoding='utf-8')
>>> f.write(u'\u76F4\u6A39\u7A32\u7530')
>>> f.close()
>>> f = open('foo.txt', 'r')
>>> f.read()
'\xe7\x9b\xb4\xe6\xa8\xb9\xe7\xa8\xb2\xe7\x94\xb0'

As you can see, the Unicode has been converted using UTF-8.
History
Date User Action Args
2009-09-25 15:10:41vinay.sajipsetrecipients: + vinay.sajip, methane
2009-09-25 15:10:41vinay.sajipsetmessageid: <1253891441.05.0.42390735918.issue6991@psf.upfronthosting.co.za>
2009-09-25 15:10:39vinay.sajiplinkissue6991 messages
2009-09-25 15:10:38vinay.sajipcreate