赞
踩
import sys def parse(line): newline = '' for i in line: if i != ',' and i != ' ': newline += i newline = newline[2:] data = int(newline,2)#字符串数据为2进制,转化为int类型的数字 #print(newline) #print(('{:02x}').format(data)) return ('{:02x}').format(data) with open(sys.argv[1]+'.exchange.txt','w') as out: with open(sys.argv[1], "r") as f: #打开文件,f表示打开的文件 line1 = f.readline() line2 = '' while line1:#文件还没结束 if line1[13] == '0' and line1[16] == '1': #print(line1[13]) line2 = f.readline() if not line2:#文件结束 break if line2[13] == '0':#再读一行,如果是0则给line1,然后重新开始 line1 = line2 continue if line2[13] == '1': if line2[16] == '1': line1 = line1[13:]#从13位开始截取数组(切片语法) data = parse(line1) data += '\n' out.write(data) line1 = f.readline() else: line1 = f.readline() else: line1 = f.readline() print("exchange end")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。