📜  python替换重音字符代码 - Python代码示例

📅  最后修改于: 2022-03-11 14:45:15.606000             🧑  作者: Mango

代码示例1
import unicodedata

def 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