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

List:       pykde
Subject:    Re: [PyKDE] unicode char with PyQt
From:       Boudewijn Rempt <boud () valdyas ! org>
Date:       2001-10-05 21:48:49
[Download RAW message or body]

-----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-----

["sitecustomize.py" (text/x-java)]

#
# sitecustomize.py - saving a useful function. Copy to the 
# somewhere on the Python path, like the site-packages directory
#
import sys

sys.setappdefaultencoding=sys.setdefaultencoding



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

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