[PyKDE] Problem with German characters

Detlev Offenbach detlev at die-offenbachs.de
Tue Oct 15 20:43:01 BST 2002


Am Dienstag, 15. Oktober 2002 20:27 schrieb jblazi:
> > Use unicode instead of str and it works ok.
> >
> > text = unicode(textedit.text())
> >
> > Detlev
>
> Then I get the next problem. Here is my code:
>
> string.split(unicode(self.widget.text.eingabe.text()),'\n')
>     tmp = unicode(self.widget.text.eingabe.text())+'\n'
>
>     try:
>         exec tmp in user_name_space
>     except:
>         txt = str(sys.exc_info()[1])
>         return
>
> Here I get the error message
>
>  ASCII encoding error: ordinal not in range(128)

Ok, there is another solution that goes a bit deeper into your Python 
setup.

Put the following lines in your sitecustomize.py or create this file in 
the site-packages directory of your python installation 
(/usr/lib/python2.2).

----------------------------------------------
#
# sitecustomize.py - saving a useful function.
#

import sys

sys.setappdefaultencoding = sys.setdefaultencoding
-------------------------------------------------

In your application include the following lines.

---------------------------------------------------
    # Set the applications string encoding
    try:
        sys.setappdefaultencoding("iso8859-1")
    except:
        pass
------------------------------------------------------

Then you can use the standard str function because Python will use the 
encoding you gave it for all string related functions.

Regards
Detlev
-- 
Detlev Offenbach
detlev at die-offenbachs.de




More information about the PyQt mailing list