[PyKDE] Using some ISO-8859-1 characters with PyQt
Ted Parnefors
ted at mtv.se
Wed Dec 20 02:10:12 GMT 2000
Den 2000.12.20 01:41:01 +0100 skrev dan:
> there is a python unicode tutorial at
> http://www.reportlab.com/i18n/python_unicode_tutorial.html
> and phil thompson wrote a little bit of help on unicode conversion for
> pyqt at
> http://www.thekompany.com/projects/pykde/pyqt_docs/x62.html
>
> hopefully you can find the gem there that is eluding me... (and if you
> do,
> please contact me and tell me how :)
>
> Dan
>
> On December 19, 2000 07:42 pm, you wrote:
> > Den 2000.12.20 01:20:03 +0100 skrev dan:
> > > did you try this?
> > >
> > > qstr = QString("åäö") # unicode qstring
> > > print `qstr` # note the backquotes
> > > ustr = unicode(`qstr`, 'utf-8') # python unicode
> > > print ustr # python knows how to print it's own unicode
> > > print ustr.encode('ISO-8859-1') # swedish charset:)
> >
> > I did just now, but "print ustr" and "print ustr.encode('ISO-8859-1')
> > both gives the same result:
> > u'\345\344\366'
I finally got it working! Here is what one has to do to convert from
QString
to any other encoding:
a=QString("åäö")
b=eval(repr(a))
print b.encode('latin-1')
I don't know why the eval should be necessary, but I guess it's because
repr(QString("åäö")) doesn't give you a unicode string, but merely the
representaion of it... sort of makes sense when you think about it but
still...
--
Ted Parnefors <ted at mtv.se>, KeyID 0x6627DEE4
PGP Fingerprint 1C39FA94703EB54A011CF18932018E256627DEE4
More information about the PyQt
mailing list