You Are Here:

Community: Developer Discussion Boards

#1 Old String encoding problem? - 2009-01-21, 15:38

Join Date: Oct 2008
Posts: 27
Davie1
Offline
Registered User
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
Reply With Quote

#2 Old Re: String encoding problem? - 2009-01-22, 05:08

Join Date: May 2007
Posts: 2,738
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Its unicode as well.

Btw, what type is loc.locationType? The rest of the code might help to solve this faster.
Reply With Quote

#3 Old Re: String encoding problem? - 2009-01-22, 11:05

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Please make sure both are same type, either unicode or non-unicode. For example u'library' and 'unicode' can be different strings.

Cheers,

--jouni
Reply With Quote

#4 Old Re: String encoding problem? - 2009-01-22, 12:13

Join Date: Oct 2008
Posts: 27
Davie1
Offline
Registered User
This is the location class:-
Code:
class location(object):
	xcoord =0
	ycoord =0
	locationType =""
I understand that they must be the same type e.g. unicode. How do you change the type to be unicode?

Note that I also remove the \n from the line that is read in from the file.

Thanks.
Reply With Quote

#5 Old Re: String encoding problem? - 2009-01-22, 12:43

Join Date: May 2007
Posts: 2,738
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Quote:
Originally Posted by Davie1 View Post
This is the location class:-
Code:
class location(object):
	xcoord =0
	ycoord =0
	locationType =""
I understand that they must be the same type e.g. unicode. How do you change the type to be unicode?

Note that I also remove the \n from the line that is read in from the file.

Thanks.
Code:
locationType =u""
Now thats unicode.

Quote:
How do you change the type to be unicode?
Just use the unicode() function to convert to unicode.

Code:
locationType=unicode(locationType)
Reply With Quote

#6 Old Re: String encoding problem? - 2009-01-22, 21:35

Join Date: Oct 2008
Posts: 27
Davie1
Offline
Registered User
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??
Reply With Quote

#7 Old Re: String encoding problem? - 2009-01-23, 13:35

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Quote:
Originally Posted by Davie1 View Post
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).
That's not unicode. Did you really try loc.locationType == u"library" as Croozeus suggested?

Quote:
Originally Posted by Davie1 View Post
I really dont know why this comparison is failing.
Any more suggestions??
Well, you might try also loc.locationType is u"library" but I doubt it would make any change. Comparison operation "is" checks whether two objects are same.

"jouni" != u"jouni",

--jouni
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia