tags:

views:

45

answers:

1

Hi,

when I run my programs from within Eclipse IDE the following piece of code works perfectly:

address_name = self.text_ctrl_address.GetValue().encode('utf-8')
self.address_list = [i for i in data if address_name.upper() in i[5].upper().encode('utf-8')]

but when running the same piece of code directly with python, I get an "UnicodeDecodeError".

What does the IDE does differently that it doesn't fall on this error ?

ps: I encode both unicode strings because it is the only way to test one string against another containing letters like ñ or ç.

Edit:

Sorry, I should have given more details: This piece of code belongs to a dialog built with WxPython. The GetValue() functions gets texts from a line edit widget and try to match this piece of text against a database. The program runs on Windows (and because of this, maybe michael Shopsin above might be right("Win-1252 to UTF-8 is a serious nuisance"). I've read many times that I should always work with unicode, avoid encoding, but if I don't encode, certain string methods don't seem to work very well depending on the characters in a word (I am in Spain, so lots of non ascii characters). By directly I meant "double clicking" the file it self, and not running from within the IDE.

A: 

Hi,

I could solve the problem changing the encoding from UTF-8 to cp1252 (Windows western europe). Apparently UTF-8 could not encode some Windows characters. Thanks to Michael Shopsin above for the insight.

The program runs on windows and uses WxPython dialog , getting values from a line edit widget and matching the string against a database.

Thank you all for the attention, and I hope this post can help people in the future with a similar problem.

Kelmer
No problem, I've dealt with this problem in a lot of languages.
Michael Shopsin