python 获取中文拼音首字母;判断文件夹是否存在

时间:2022-05-13 23:59:02

1.如何获取中文字符串的首字母

import pinyin

#输入name
def get_pinyin_first_alpha(name):
return "".join([i[0] for i in pinyin.get(name, " ").split(" ")])

2. 判断文件夹是否存在, 存在删除,不存在创建

import os
import shutil def create_folder(train_data_path ):
if os.path.exists(train_data_path):
shutil.rmtree(train_data_path) os.mkdir(train_data_path)