Monday, September 18, 2006

unicode gotchas

Hum, I don't have any problems, and I don't do anything special ...

- I use PostgreSQL, so I created my database using UTF-8 encoding.
- my Python modules start with "# -*- coding: utf-8 -*-".
- all my modules and my templates are utf-8 encoded (I use Vim, so I
use ":set encoding=utf-8", but it should work with any good
text-editor).

The only 'encoding trick' I use is when I want to print an exception,
catched from a bad database query. I need to do something like this :

===============
except Exception, detail:
print "blablabla : %s" % str(detail).decode('latin1')
return
===============

... since the exception message (which is in french) seems to be latin1
encoded.

That's all :)

Jonathan

ps : it should be the same with sqlite

No comments: