将眼底图片生成的txt文件进行格式化处理
# -*- coding: utf-8 -*- """ 将图片转换生成的txt文件进行格式化处理 """ import os import re import sys def txtChange(): ifn = r"extract.txt"#待处理的txt文件 ofn = r"testingData.txt"#处理好后生成的txt文件 infile = open(ifn,'rb') outfile = open(ofn,'wb') i = 0 for eachline in infile.readlines(): lines = re.split("\n| ",eachline) print lines for temp in lines: if i == 7: i = 0 outfile.write('\n') elif i < 7: outfile.write(temp+' ') i = i + 1 infile.close outfile.close if __name__=='__main__': txtChange()