UnicodeDecodeError

A

ash

hi,
one of the modules in my programs stopped wroking after i upgraded from
python 2.3 to 2.4. I also changed my wxPython to unicode supported one
during the process.
what the module essentially does is search for a stirng pattern form a
list of strings.
this is the function:

def srchqu(self):
for i in range(1,len(qu)):#qu is the list of strings
if qu[0].lower().find(self.query)==-1:
pass
else:
#do some stuff here

I get this error message on calling the function:

Traceback (most recent call last):
File "E:\mdi\search.py", line 86, in OnSrchButton
self.srchqu()
File "E:\mdi\search.py", line 97, in srchqu
if qu[0].lower().find(self.query)==-1:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position
66: ordinal not in range(128)

what is the problem and the solution? thanks in advance for any help.

Ashoka
 
F

Fredrik Lundh

ash said:
one of the modules in my programs stopped wroking after i upgraded from
python 2.3 to 2.4. I also changed my wxPython to unicode supported one
during the process.
what the module essentially does is search for a stirng pattern form a
list of strings.
this is the function:

def srchqu(self):
for i in range(1,len(qu)):#qu is the list of strings
if qu[0].lower().find(self.query)==-1:
pass
else:
#do some stuff here

I get this error message on calling the function:

Traceback (most recent call last):
File "E:\mdi\search.py", line 86, in OnSrchButton
self.srchqu()
File "E:\mdi\search.py", line 97, in srchqu
if qu[0].lower().find(self.query)==-1:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position
66: ordinal not in range(128)

what is the problem and the solution? thanks in advance for any help.


one of qu[0] or self.query is a unicode string, and the other is an 8-bit
string that contains something that's not ASCII.

to make the code do what you do, make sure to decode the 8-bit strings
into Unicode strings.

</F>
 
A

ash

Thanks Fredrik, i decoded both qu[0] and self.query to latin_1
(self.query.decode("latin_1")) and i am not getting the error now.

If you dont mind, I have another question for you. I use wxPython for
GUI development. When i use a string containing "&" character as a
label for statictext, the "&" does'nt appear.It is replaced by a short
_. I have tried different encodings but have no success. what should i
do so that "&" appears on screen?

thanks once againg for your help.

regards,
Ashoka
 
F

Fredrik Lundh

ash said:
If you dont mind, I have another question for you. I use wxPython for
GUI development. When i use a string containing "&" character as a
label for statictext, the "&" does'nt appear.It is replaced by a short
_. I have tried different encodings but have no success. what should i
do so that "&" appears on screen?

I don't use wxPython, but & is commonly used by GUI toolkits to place
an underscore under a menu choice, to indicate what hotkey to use
for that menu choice. e.g. "&Save" or "E&xit".

I don't know how to escape that in wxPython. it might be a good idea
to post your question on some wxpython mailing list:

http://www.wxpython.org/maillist.php

</F>
 
J

Jarek Zgoda

ash napisa³(a):
If you dont mind, I have another question for you. I use wxPython for
GUI development. When i use a string containing "&" character as a
label for statictext, the "&" does'nt appear.It is replaced by a short
_. I have tried different encodings but have no success. what should i
do so that "&" appears on screen?

Double your ampersand character.
 
A

ash

Thanks Jarek, doubling worked. I thought it was a problem with encoding
but didnt think of escaping it. thanks a lot.
Thanks for Fredrik too for taking the trouble.
Regards,
Ashoka
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top