On Tue, 26 Apr 2005 11:41:01 +0200, Peter Otten wrote: > Dumbkiwi wrote: > >> 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') > > data is now a unicode string. > > >> 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? > > Just encode the data in the target encoding before passing it to > os.popen(): > > test = os.popen('kdialog --inputbox %s' % data.encode("utf-8")) > > Peter
I had tried that, but then the text looks like crap. The text I'm using for this is Polish, and there are a lot of non-English characters in there. Using this method results in some strange characters - basically it looks like a file encoded in utf-8, but displayed using iso-8859-1. Is this the best I can do? Thanks for your help. Matt -- http://mail.python.org/mailman/listinfo/python-list