如何将.txt转换成python中的.xls?

with open(output_filename, 'w') as f_output: for dirpath, dirnames, filenames in os.walk(directory): for filename in filenames: if filename.startswith('VCALogParser_output'): cur_file = os.path.join(dirpath, filename) with open(cur_file, "r") as f_input: f_input.seek(0, os.SEEK_END) backup = min(back_up , f_input.tell()) f_input.seek(-backup, os.SEEK_END) last_lines = ''.join(f_input.readlines()[-6:]) try: summary = ', '.join(re.search(r'(\d+ warning\(s\)).*?(\d+ error\(s\)).*?(\d+ scenarios\(s\) FAILED)', last_lines, re.S).groups()) except AttributeError: summary = "VCA DID NOT START" f_output.write('{}: {}\n'.format(filename, summary)) 

上面的代码是通过文件parsing并从文件中读取一些数据,并以.txt的forms将其作为输出。 但是我想把它当成一个.xls。 谁能告诉我如何将下面的.txt转换为.xls?

以.txt格式输出:

 VCALogParser_output_ARW.log: 12 warning(s), 85 error(s), 32 scenarios(s) FAILED VCALogParser_output_CZC.log: 18 warning(s), 33 error(s), 14 scenarios(s) FAILED VCALogParser_output_DUN.log: VCA DID NOT START VCALogParser_output_FRC.log: 12 warning(s), 34 error(s), 12 scenarios(s) FAILED VCALogParser_output_GED.log: 39 warning(s), 79 error(s), 27 scenarios(s) FAILED VCALogParser_output_MNT.log: 41 warning(s), 76 error(s), 33 scenarios(s) FAILED VCALogParser_output_NON.log: 25 warning(s), 50 error(s), 14 scenarios(s) FAILED VCALogParser_output_PTB.log: VCA DID NOT START VCALogParser_output_PTP.log: 31 warning(s), 35 error(s), 21 scenarios(s) FAILED VCALogParser_output_SPM.log: 58 warning(s), 150 error(s), 57 scenarios(s) FAILED VCALogParser_output_SWS.log: 14 warning(s), 23 error(s), 11 scenarios(s) FAILED 

尝试xlutils模块

“使用需要xlrd和xlwt的Excel文件的实用程序”