Encoding Questions

"Martin v. Löwis" martin at v.loewis.de
Wed Apr 20 02:30:50 EDT 2005


jalil at feghhi.com wrote:
> thanks for the replies. As for why I set my default encoding to utf-8
> in python, I did it a while ago and I think I did it because when I was
> reading some strings from database in utf-8 it raised errors b/c there
> were some chars it could recongnize in standard encoding. When I made
> the change, the error didn't happen anymore.
> 
> Does it make sense? 

No. If reading the strings from the database already gives an exception
(i.e. without any processing of these strings), that is a bug in the
database. It is also unlikely that this is what actually happened.

More likely, you are reading the strings from the database, and then
combining them explicitly with Unicode strings. Instead of changing
the default encoding, you should tell your database adapter to return
the strings as Unicode objects; if this is not supported, you should
convert them to Unicode objects in the process of reading them.

Regards,
Martin



More information about the Python-list mailing list