python: 用unidecode实现拉丁字母转英文
一,安装第三方库
$ pip install unidecode
二,代码:
import unidecode
def latin_to_ascii(text):
return unidecode.unidecode(text)
# 示例
text = "â é ë ó ñ" # 德语示例
ascii_text = latin_to_ascii(text)
print(ascii_text)
三,测试效果:
$ python3 code.py
a e e o n
浙公网安备 33010602011771号