python读写各种文件

python读写各种文件

  • 读写txt文件
  • 读写xls表格文件

读写txt文件

    with open(txtFilePath,'w') as file:
        for str in results:
            file.write(str)
        for str in parallel_results:
            file.write(str)

    with open(file_path, 'r') as file:
        lines = file.readlines()  # 读取所有行并将其存储在一个列表中
        #统计所有失败用例的名称
        for line in lines:
        	print(line)

读写xls表格文件

参考链接

import xlwt
book = xlwt.Workbook(encoding='utf-8', style_compression=0)
    col = ('用例类别','用例名称','失败原因')
    sheet = book.add_sheet('parallelschedule0失败用例统计', cell_overwrite_ok=True)
    for i in range(0, 3):
        sheet.write(0, i, col[i])
    row = 1
    for str in results:
        sheet.write(row,1,str)
        row += 1
    for str in parallel_results:
        sheet.write(row,1,str)
        row += 1
    book.save(excelFilePath)

你可能感兴趣的:(python,python)