import os RESULTS_PATH = r"C:\Users\wengq\Desktop\QY项目\mindie_test_results" def main(): tp1_result = "" tp8_result = "" for dirpath, dirnames, filenames in os.walk(RESULTS_PATH): for filename in filenames: if "tp1_result" in filename: with open(os.path.join(dirpath, filename), 'r', encoding='utf-8') as file: file.readline() tp1_result += file.readline() elif "tp8_result" in filename: with open(os.path.join(dirpath, filename), 'r', encoding='utf-8') as file: file.readline() tp8_result += file.readline() print(tp1_result) print(tp8_result) if __name__ == "__main__": main()