| Reply | « Previous Thread | Next Thread » |
|
Hi,
I was wondering if anyone knew what encoding a string read from a file by a python program is in? I am having trouble comparing to string values, 1 of which is an attribute of a class i have defined. Heres the part of the code that is giving me the problem:- Code:
def DrawWedge(loc,im,x,y,dir):
colour =0x000000#black
if(loc.locationType=='library'):
colour = 0xff0000#red
print colour
elif(loc.locationType=='coffee'):
colour = 0x800000#darkred
print colour
elif(loc.locationType=='tourist'):
colour = 0x0000FF#blue
print colour
else:
colour =0x000000#black
print "else"
print colour
|
|
Its unicode as well.
Btw, what type is loc.locationType? The rest of the code might help to solve this faster. |
|
Please make sure both are same type, either unicode or non-unicode. For example u'library' and 'unicode' can be different strings.
Cheers, --jouni |
|
This is the location class:-
Code:
class location(object): xcoord =0 ycoord =0 locationType ="" ![]() Note that I also remove the \n from the line that is read in from the file. Thanks. |
|
Quote:
Code:
locationType =u"" Quote:
Code:
locationType=unicode(locationType) |
|
Hi,
I have tried converting both strings that I want to compare into unicode and it still fails(I know the strings are the same but loc.locationType=="library" is false instead of True). I have just went through the code step-by-step using the python shell and everything worked as expected. I really dont know why this comparison is failing. ![]() ![]() Any more suggestions?? |
|
Quote:
Quote:
"jouni" != u"jouni", --jouni |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Problem in sending encrypted string via CSmsHandler class | michaelnewyork | General Symbian C++ | 2 | 2008-12-25 13:41 |
| Problem with c++ string | lucafr | General Symbian C++ | 2 | 2008-09-25 23:20 |
| utf-16 encoding problem | eta | Mobile Java General | 0 | 2008-07-19 16:21 |
| Encoding problem? | lucazd | Mobile Java Tools & SDKs | 3 | 2007-06-12 20:24 |
| MMS binary encoding, charset problem | x_2001 | General Messaging | 2 | 2002-12-26 14:14 |