[PyQt] Accented characters

Christoph Burgmer chrislb at gmx.de
Fri May 2 10:46:40 BST 2008


Am Donnerstag, 1. Mai 2008 schrieb alteo_gange:
> Le jeudi 01 mai 2008, alteo_gange a écrit :
> > Hi,
> >
> > could you complete the next bit of code please?
> >
> > 1) File selection (the file's name is accented: ex. animé.txt)
> > file = QFileDialog.getOpenFileName(None, "Open"),".","All files (*.*))
> > 2) Print file's name in a terminal
> > ???
> >
> > It seems easy... too easy...
>
> print a.toUtf8()
> -> /home/login/animé.txt

If I'm not wrong this "trick" will only work for people who use utf8 as 
default encoding.

You may want to read about Python's way of dealing with encodings and Unicode, 
but that's off topic here.

Little hint:

_, system_encoding = locale.getdefaultlocale()

print unicode(your_string).encode(system_encoding)

Christoph



More information about the PyQt mailing list