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

 

posted @ 2025-12-04 19:30  刘宏缔的架构森林  阅读(2)  评论(0)    收藏  举报