[Tutor] Encoding

spir denis.spir at gmail.com
Sun Mar 7 14:29:11 CET 2010


On Sun, 7 Mar 2010 13:23:12 +0100
Giorgio <anothernetfellow at gmail.com> wrote:

> One more question: Amazon SimpleDB only accepts UTF8.
[...]
> filestream = file.read()
> filetoput = filestream.encode('utf-8')

No! What is the content of the file? Do you think it can be a pure python representation of a unicode text?

uContent = inFile.read().decode(***format***)
<process, if any>
outFile.write(uContent.encode('utf-8'))

input -->decode--> process -->encode--> output

This gives me an idea: when working with unicode, it would be cool to have an optional format parameter for file.read() and write. So, the above would be:

uContent = inFile.read(***format***)
<process, if any>
outFile.write(uContent, 'utf-8')

Or, maybe even better, the format could be given as third parameter of file open(); then any read or write operation would directly convert from/to the said format. What do you all think?


denis
-- 
________________________________

la vita e estrany

spir.wikidot.com



More information about the Tutor mailing list