Python - non-English characters don't work in one case

114 views Asked by At

Despite the fact I tried to find a solution to my problem both on english and my native-language sites I was unable to find a solution. I'm querying an online dictionary to get translated words, however non-English characters are displayed as e.g. x86 or x84. However, if I just do print(the_same_non-english_character) the letter is displayed in a proper form. I use Python 3.3.2 and the HTML source of the site I extract the words from has charset=UTF-8 set. Morever, if I use e.g. replace("x86", "non-english_character"), I don't get anything replaced, but replacing of normal characters works.

1

There are 1 answers

5
Padraic Cunningham On

you need to escape with a \:

In [1]: s= "\x86"

In [2]:  s.replace("\x86","non-english_character")
Out[2]: 'non-english_character'