[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] Using some ISO-8859-1 characters with PyQt
From:       Ted Parnefors <ted () mtv ! se>
Date:       2000-12-20 2:10:12
[Download RAW message or body]

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@mtv.se>, KeyID 0x6627DEE4
 PGP Fingerprint 1C39FA94703EB54A011CF18932018E256627DEE4



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic