Help with this problem (ascii, utf-8,encode,decode...)
#1
Exclamation 
Im going mad...
I have a big trouble working with strings with special caracters.
An example of my problem:


Code:
list.append("Exámple")  
        seleccion= xbmcgui.Dialog()
        number= seleccion.select(selecciona,list)
    

name = list[number]


Code:
print name

=

Exámple


Code:
self.functionExample(name)

Code:
def functionExample(self,n):
if n=="Exámple":
print "WORKS WELL"


Problem is n == Exámple returns FALSE but n=Exámple and print n prints Exámple.


I know problem is the special caracter "á" and i tried to encode and decode to utf-8 the variable name.
If i try:

Code:
name=name.encode("utf-8")

ascii' codec can't decode byte in position 3: ordinal not in range(128)

name=name.decode("utf-8")
utf8' codec can't decode bytes in position  : invalid data


I have a seriuos problem with codification, i need help with this.
Another problem (but i think is the same problem with the same solution) is when I have a label and i setLabel a word with especial caracter, if i only set the variable with special caracter, lableel shows perfect. Example:

Code:
self.getControl(self.lbl_example).setLabel(name)
lbl_example shows Exámple

BUT

self.getControl(self.lbl_example).setLabel("The name is %s",%(name))
lbl_example shows The name is  Ex/..mple


My scraper have the line # -*- coding: utf-8 -*- on top.
Im going mad with this problem....Sad


Anyone could help me please??

Thanks in advance.
Reply
#2
see the convert.py lib made by frostbox you'll find it in most of my plugins.
Reply
#3
If name is actually of type "unicode" then you should be able to make that comparison work by prefixing "Exámple" with a u (i.e. u"Exámple").
Reply
#4
ppic Wrote:see the convert.py lib made by frostbox you'll find it in most of my plugins.
Thanks a lot, i have the convert.py from one of yours plugin but I only be able to convert Exámple to Example using translate_string function. I want to compare a variable type string with a special caracter WITH a string with a special caracter.
Can you help me?
Then, I want to be able to show in a label a text and the variable with the special caracter.

spbogie Wrote:If name is actually of type "unicode" then you should be able to make that comparison work by prefixing "Exámple" with a u (i.e. u"Exámple").
Thanks but:
if name==u"Exámple":

doesnt work, error script.
Reply
#5
Somebody to help me?
Thanks
Reply
#6
have you tried with setEntityOfCharset in same lib?

for your comparison, you can convert both side, convert will work the same for both so comparison should be ok.
Reply

Logout Mark Read Team Forum Stats Members Help
Help with this problem (ascii, utf-8,encode,decode...)0