How to store ASCII encoded python string?

Fredrik Lundh fredrik at pythonware.com
Mon Aug 28 17:14:31 EDT 2006


micahc at gmail.com wrote:

> Fredrik Lundh wrote:
>> 3) convert the data to Unicode before passing it to the database
>> interface, and leave it to the interface to convert it to whatever
>> encoding your database uses:
>>
>>      data = ... get encoded string from email ...
>>      text = data.decode("iso-8859-1")
>>      ... write text to database ...
> 
> Wouldn't that have to assume that all incoming data is in iso-8859-1?
> If someone sends me an email with chinese characters would that still
> work (I don't know the character set at data insert time)?

if you're reading mail, chances are that you know the encoding (it's 
specified in the message headers).

or are you saying that you're treating the mail as binary data?  if so, 
why are you trying to store that in a *text* field in the database?

</F>




More information about the Python-list mailing list