Convert a Unicode string to a string in Python (containing extra symbols)

Convert a Unicode string to a string in Python (containing extra symbols)

See unicodedata.normalize

title = uKlüft skräms inför på fédéral électoral große
import unicodedata
unicodedata.normalize(NFKD, title).encode(ascii, ignore)
Kluft skrams infor pa federal electoral groe

You can use encode to ASCII if you dont need to translate the non-ASCII characters:

>>> a=uaaaàçççñññ
>>> type(a)
<type unicode>
>>> a.encode(ascii,ignore)
aaa
>>> a.encode(ascii,replace)
aaa???????
>>>

Convert a Unicode string to a string in Python (containing extra symbols)

>>> text=uabcd
>>> str(text)
abcd

If the string only contains ascii characters.

Leave a Reply

Your email address will not be published. Required fields are marked *