美文网首页
[Python]使用glob递归的查找所有文件

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

作者: VanJordan | 来源:发表于2019-07-05 14:59 被阅读0次
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')
            

相关文章

网友评论

      本文标题:[Python]使用glob递归的查找所有文件

      本文链接:https://www.haomeiwen.com/subject/tckehctx.html