kdialog and unicode

Dumbkiwi dmbkiwi at yahoo.com
Tue Apr 26 05:21:58 EDT 2005


I'm trying to get python, unicode and kdialog to play nicely together.
This is a linux machine, and kdialog is a way to generate dialog boxes in
kde with which users can interact (for example input text), and you can
use the outputted text in your script.

Anyway, what I'm doing is reading from a utf-8 encoded text file using the
codecs module, and using the following:

data = codecs.open('file', 'r', 'utf-8')

I then manipulate the data to break it down into text snippets.

Then I run this command:

>>> test = os.popen('kdialog --inputbox %s' %(data))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode character u'\u017a' in
position 272: ordinal not in range(128)

I would really like kdialog display the text as utf-8.  However, it seems
that python is trying to pass the utf-8 encoded data as ascii, which
obviously fails because it can't deal with the utf-8 encoded text.  Is it
possible to pass the text out to kdialog as utf-8, rather than ascii?

Or have I completely misunderstood the whole process, in which case, can
you please enlighten me.

Matt



More information about the Python-list mailing list