Dealing with "funny" characters

Gert-Jan python at gjdenbesten.nl
Sat Oct 20 10:04:22 EDT 2007


sophie_newbie schreef:
> 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?


It seems you'll have to use Unicode in your program rather than 'plain' 
strings.

Before storing an unicode textstring in a database or a file, you must 
encode it using an appropriate encoding/codepage, for example:

outputstring = unicodeobject.encode('utf-8')


This is not an easy subject. But it isn't very hard either. Please 
search the Python documentation using these keywords: Unicode, decoding 
and encoding.


But you should read this first: 
http://www.joelonsoftware.com/articles/Unicode.html
It's an entertaining introduction to the world of codepages and unicode :-)


Regards,
Gert-Jan




More information about the Python-list mailing list