[PyKDE] unicode two-way conversion

Mateusz Korniak mateusz at ant.gliwice.pl
Tue Oct 25 11:28:41 BST 2005


On Tuesday 25 of October 2005 12:13, Sebastian Kügler wrote:
> Hi,
>
> (I'm posting to this list since I think it's likely that someone here ran
> across the same problem.)
>
> I'm working on a database frontend for a postgresql database, and I'm
> having an issue with unicode characters that I've put into the Qt UI.
>
> When I read the data from the widget, I'm not able to insert strings into
> the database using unicode. I can replace the offending characters with
> 'string'.encode('ascii', 'xmlcharrefreplace').

Encode to (and back from) utf-8.
Remember only that utf-8 representation is longer than number of chars in 
unicode string if any non 7bit ascii char is used.
Also make sure that Yours DB iface allows to use 8bit encoding (like 
iso-8859-1/2).

> So what I basically need is a two-way conversion between unicode strings
> and ascii (or at least something that is easily usable together with
> psycopg and postgres' character fields.
>
> Attached scriptlet should show that problem.

Another solution (and prolly better) to You, may be to create unicode 
Postgresql database and do not care about encoding anymore at all.

-- 
Mateusz Korniak
"Black holes are where God divided by zero." - Steven Wright




More information about the PyQt mailing list