Dealing with "funny" characters

Paul Hankin paul.hankin at gmail.com
Sat Oct 20 10:04:10 EDT 2007


On Oct 20, 2:13 pm, sophie_newbie <paulgeele... at gmail.com> wrote:
> Hi, I want to store python text strings that characters like "é" "Č"
> in a mysql varchar text field. Now my problem is that mysql does not
> seem to accept these characters. I'm wondering if there is any way I
> can somehow "encode" these characters to appear as normal characters
> and then "decode" them when I want to get them out of the database
> again?

Use unicode strings, and use the 'encode' and 'decode' methods. Mysql
has utf8 support for varchars, so that seems a likely encoding to use.
If you're stuck with ascii, you can use 'unicode_escape' if you're
only accessing it from python.

But first read this excellent article on 'funny' characters:
http://www.joelonsoftware.com/articles/Unicode.html

--
Paul Hankin




More information about the Python-list mailing list