473,387 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

UnicodeDecodeError

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[i][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[i][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

Nov 30 '05 #1
5 5574
"ash" wrote:
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[i][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[i][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[i][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>

Nov 30 '05 #2
ash
Thanks Fredrik, i decoded both qu[i][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

Dec 1 '05 #3
"ash" wrote:
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>

Dec 1 '05 #4
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.

--
Jarek Zgoda
http://jpa.berlios.de/
Dec 1 '05 #5
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

Dec 2 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ruslan | last post by:
Hi, everybody. In this excerpt of code enc = 'some_type_of_encoding' def _encode(v): if isinstance(v, UnicodeType): v = v.encode(v) return v
4
by: Robin Siebler | last post by:
I have no idea what is causing this error, or how to fix it. The full error is: Traceback (most recent call last): File "D:\ScriptRuntime\PS\Automation\Handlers\SCMTestToolResourceToolsBAT.py",...
2
by: dbri.tcc | last post by:
Hello I am getting somewhat random UnicodeDecodeError messages in my program. It is random in that I will be going through a pysqlite database of records, manipulate the results, and it will...
4
by: Robin Haswell | last post by:
Okay I'm getting really frustrated with Python's Unicode handling, I'm trying everything I can think of an I can't escape Unicode(En|De)codeError no matter what I try. Could someone explain to...
1
by: Karl | last post by:
error msg: Mod_python error: "PythonHandler mod_python.publisher" Traceback (most recent call last): File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch...
4
by: Oleg Parashchenko | last post by:
Hello, I'm working on an unicode-aware application. I like to use "print" to debug programs, but in this case it was nightmare. The most popular result of "print" was: UnicodeDecodeError:...
3
by: Jorgen Bodde | last post by:
Hi All, I am relatively new to python unicode pains and I would like to have some advice. I have this snippet of code: def playFile(cmd, args): argstr = list() for arg in...
0
by: Jorgen Bodde | last post by:
Hi Edwin, Filemask is obvious as it is assigned in the python code itself. It is "%file%". The idea is that the file clicked is substituted for the "%file%" by the replace action. The file that...
3
by: Gilles Ganault | last post by:
Hello I'm getting this error while downloading and parsing web pages: ===== title = m.group(1) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 48: ordinal not in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.