[PyKDE] unicode char with PyQt

Boudewijn Rempt boud at valdyas.org
Fri Oct 5 21:48:49 BST 2001


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 05 October 2001 13:25, Tobias Unruh wrote:
> Hi,
>
> I tried to save a text with ASCII char ord(char)>128 (e.g. german ue)
> using the application.py example of PyQt 2.5. The result is:
>
> Traceback (most recent call last):
>   File "./application.py", line 194, in save
>     self.saveAs()
>   File "./application.py", line 214, in saveAs
>     self.save()
>   File "./application.py", line 203, in save
>     f.write(str(self.e.text()))
>   File "/usr/local/lib/python2.1/site-packages/qt.py", line 320, in
> __str__
>     return str(self.sipThis)
> UnicodeError: ASCII encoding error: ordinal not in range(128)
>
> I have similar problems with my own programs. Can someone tell me how to
> convert a QString which contains unicode char to a python string
> containing unicode char?
>
> Tobias


Oh, yes I can... It's the source of much chagrin to me. Either Pytbon
should include a function to set the default encoding to utf-8, or
applying unicode() to a QString should use the utf-8 encoding...

Anyway, rather than steal time that's needed for editing the PyQt
book, I'll point you to my chapter on Strings and QStrings, which
deals with this matter _in extenso_:

  http://stage.linuxports.com/pyqt/c877.htm

Quick summary: put the attached script in the Pythonpath for your
app. (There's a mistake in the current text, fixed in the version 
I'm editing now, that says that this script has to be in the site-packages
directory. Anywhere on the python path is OK.)
- -- 

Boudewijn Rempt | http://www.valdyas.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7vg4aN8fj6DnPxOgRAsX6AJ0UKNksb0yDL4ogX0/C0dzKMFmv+wCgpFOQ
/MKDntb2b6Y3Z51ZJycCnYc=
=yKxT
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sitecustomize.py
Type: text/x-java
Size: 191 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20011005/5fad8e19/sitecustomize.bin


More information about the PyQt mailing list