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 snaury
Recipients snaury
Date 2016-05-29.17:41:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1464543679.71.0.415502254928.issue27154@psf.upfronthosting.co.za>
In-reply-to
Content
There's a regression in file.writelines behavior for binary files when writing unicode strings, which seems to have first appeared in Python 2.7.7. The problem is that when writing unicode strings the internal representation (UCS2 or UCS4) is written instead of the actual text, which also directly contradicts documentation, which states "This is equivalent to calling write() for each string". However on Python 2.7.7+ they are no longer equivalent:

>>> open('testfile.bin', 'wb').writelines([u'Hello, world!'])
>>> open('testfile.bin', 'rb').read()
'H\x00e\x00l\x00l\x00o\x00,\x00 \x00w\x00o\x00r\x00l\x00d\x00!\x00'
>>> open('testfile.bin', 'wb').write(u'Hello, world!')
>>> open('testfile.bin', 'rb').read()
'Hello, world!'

This code worked correctly no Python 2.7.6.
History
Date User Action Args
2016-05-29 17:41:19snaurysetrecipients: + snaury
2016-05-29 17:41:19snaurysetmessageid: <1464543679.71.0.415502254928.issue27154@psf.upfronthosting.co.za>
2016-05-29 17:41:19snaurylinkissue27154 messages
2016-05-29 17:41:19snaurycreate