在Python 3中,用相应的非重音字母替换重音字母

在Python 3中,用相应的非重音字母替换重音字母,python,replace,diacritics,Python,Replace,Diacritics,我不确定这种流行的方法在Python3中是否有效,因为Python3中没有unicode 因此,在Python3中,如何用相应的非重音字母替换重音字母 比如说, sentence = 'intérêt' 到 链接的答案引用了第三方模块unidecode,而不是Python 2的unicode类型 $ python3 Python 3.7.1 (default, Nov 19 2018, 13:04:22) [Clang 10.0.0 (clang-1000.11.45.5)] on darwi

我不确定这种流行的方法在Python3中是否有效,因为Python3中没有unicode

因此,在Python3中,如何用相应的非重音字母替换重音字母

比如说,

sentence = 'intérêt'


链接的答案引用了第三方模块
unidecode
,而不是Python 2的
unicode
类型

$ python3
Python 3.7.1 (default, Nov 19 2018, 13:04:22)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import unidecode
>>> unidecode.unidecode('intérêt')
'interet'

unidecode
是一个第三方模块,在Python3中运行良好。它独立于将Python2的
unicode
类型重命名为
str
。另请参见
$ python3
Python 3.7.1 (default, Nov 19 2018, 13:04:22)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import unidecode
>>> unidecode.unidecode('intérêt')
'interet'