breamoreboy at yahoo.co.uk
Thu Feb 13 01:59:16 CET 2014
On 13/02/2014 00:44, Tim Chase wrote:
> On 2014-02-12 23:36, Mark Lawrence wrote:
>> On 12/02/2014 22:14, Tim Chase wrote:
>>> To be pedantic, you can only write *bytes* to files, so you need
>>> to serialize your lists (or other objects) to strings and then
>>> encode those to bytes; or skip the string and encode your
>>> list/object directly to bytes.
>> >>> f = open('test.txt', 'w')
>> >>> f.write('a string')
>> >>> f.close()
>>>> s = "\u3141" # HANGUL LETTER MIEUM
>>>> f = open('test.txt', 'w')
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> UnicodeEncodeError: 'ascii' codec can't encode character '\u3141' in
> position 0: ordinal not in range(128)
> Just because the open() call hides the specification of how Python
> should do that encoding doesn't prevent the required encoding from
> happening. :-)
Which clearly reinforces the fact that what you originally said is
incorrect, I don't have to do anything, Python very kindly does things
for me under the covers.
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
This email is free from viruses and malware because avast! Antivirus protection is active.
More information about the Python-list