[Python]使用glob递归的查找所有文件

2019-07-05  本文已影响0人  VanJordan
import nltk.data
import glob
root_dir = "~/data/*/"

txt_path_list = glob.glob(root_dir+'*.txt',recursive=True)
print(txt_path_list)

for this_file in txt_path_list:
    with open(this_file,'r',encoding='utf8') as f,open(this_file+'.tokenized','w',encoding='utf8') as fw:
        for line in f:
            fw.write(' '.join(nltk.word_tokenize(line))+'\n')
            

上一篇 下一篇

猜你喜欢

热点阅读