Python 遍历文件夹下的所有文件

直接上代码

import os
path = "../data"
for dir_path, dir_names, file_names in os.walk(path):
    for file_name in file_names:
        print(file_name)
        path = os.path.join(dir_path, file_name)
        qq_file = open(path)
        lines = qq_file.readlines()
        for line in lines:
            str = line.strip('\n').strip()
            print(str)

 

你可能感兴趣的:(Python)