Python 将汉字转为拼音

https://blog.csdn.net/weixin_42464956/article/details/110927073

##pip install xpinyin -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
from xpinyin import Pinyin
import os

def is_Chinese(ch):
return True if '\u4e00' <= ch <= '\u9fff' else False

p = Pinyin()
dirs=os.getcwd()
for f in os.listdir(dirs):
if os.path.isdir(os.path.join(dirs, f)) and is_Chinese(f[0]):
res = p.get_pinyin(f)
res=res.replace('-', '')
print(res)

posted @ 2022-05-27 09:26  笨笨和呆呆  阅读(50)  评论(0)    收藏  举报