Encoding problem

Hi,

I have the following code that is processing to the encode of a sting using CP1252

sDefectiveString = node.getAttribute(‘defectiveString’).encode(‘CP1252’)
print sDefectiveString

When I print the string I’m getting the following printed baie/détroit d’'Hudson

if I sorted the encoded sDefectiveString in a variable like:

a = sDefectiveString

The sorted value is baie/d\x82troit d’'Hudson

How can I get the printed encoded value as it is printed (baie/détroit d’'Hudson) ?

Thanks.

Rabbi

Isn’t it that value? It is just showing you the UNICODE value of the é in your stored variable.

Probably because of the way python stores its variables. \x82 ie equal to é, so the value stored, is indeed the value you wanted it to store…

Thanks cpradio.

I have set the py file header with # -- coding: utf-8 -- and after, I did a test storing é in a variable a = ‘é’ en the stored value in the variable is \xe9 …

The problem is I have to retrieved the value baie/détroit d’‘Hudson in a database table, but if
the string contains something like baie/d\xe9 troit d’'Hudson the record won’t be found…

I don’t get why when I use the print instruction print is printing the accented characters…

I think I’m really stuck…

Thanks

Thanks

Maybe it’s the collation causing a problem?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.