[Tutor] Encoding
Dave Angel
davea at ieee.org
Sun Mar 7 20:37:30 CET 2010
Giorgio wrote:
> 2010/3/7 spir <denis.spir at gmail.com>
>
>
> One more question: Amazon SimpleDB only accepts UTF8.
>
> So, let's say i have to put into an image file:
>
>
Do you mean a binary file with image data, such as a jpeg? In that
case, an emphatic - NO. not even close.
> filestream = file.read()
> filetoput = filestream.encode('utf-8')
>
> Do you think this is ok?
>
> Oh, of course everything url-encoded then
>
> Giorgio
>
>
>
Encoding binary data with utf-8 wouldn't make any sense, even if you did
have the right semantics for a text file.
Next problem, 'file' is a built-in keyword. So if you write what you
describe, you're trying to call a non-static function with a class
object, which will error.
Those two lines don't make any sense by themselves. Show us some
context, and we can more sensibly comment on them. And try not to use
names that hide built-in keywords, or Python stdlib names.
If you're trying to store binary data in a repository that only permits
text, it's not enough to pretend to convert it to UTF-8. You need to do
some other escaping, such as UUENCODE, that transforms the binary data
into something resembling text. Then you may or may not need to encode
that text with utf-8, depending on its character set.
DaveA
More information about the Tutor
mailing list