How to replace accented characters? How to replace accented characters? python python

How to replace accented characters?


Please Use the below code:

import unicodedatadef strip_accents(text):    try:        text = unicode(text, 'utf-8')    except NameError: # unicode is a default on python 3         pass    text = unicodedata.normalize('NFD', text)\           .encode('ascii', 'ignore')\           .decode("utf-8")    return str(text)s = strip_accents('àéêöhello')print s


import unidecodesomestring = "àéêöhello"#convert plain text to utf-8u = unicode(somestring, "utf-8")#convert utf-8 to normal textprint unidecode.unidecode(u)

Output:

aeeohello


Alpesh Valaki's answer is the "nicest", but I had to do some adjustments for it to work:

# I changed the importfrom unidecode import unidecodesomestring = "àéêöhello"#convert plain text to utf-8# replaced unicode by unidecodeu = unidecode(somestring, "utf-8")#convert utf-8 to normal textprint(unidecode(u))