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

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


See unicodedata.normalize

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


You can use encode to ASCII if you don't need to translate the non-ASCII characters:

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


>>> text=u'abcd'>>> str(text)'abcd'

If the string only contains ascii characters.


matomo