如何在 Python 中替换 unicode 字符串中的非 ascii 字符?
这是我对给定输入的输出:
音乐 -> 音乐
纸箱 -> 纸箱
卡诺 -> 卡诺
Myaybe 有一个字典,其中 'á' 是键,'a' 是值?
最佳答案
如果您只想将重音字符降级为非重音字符:
>>> import unicodedata
>>> unicodedata.normalize('NFKD', u"m\u00fasica").encode('ascii', 'ignore')
'musica'
关于python - 从 Python 中的 unicode 字符串替换非 ascii 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3704731/