python将数据文件分离并输出新的文件

#     file = open('C:/Users/lynxi/Desktop/2ns_fsdb_coe/temp.txt', 'r')
# except FileNotFoundError:
#     print('File is not found')
# else:
#     lines = file.readlines()
#     for line in lines:
#         num = line.split(' ')[0]
#         coe_numm = coe(eval(num)).upper()
#         coe_num = coe_numm[2:]
#         print(coe_num)
#coding=utf8
import os


def file_name1(in_file,out_file):
    lines = in_file.readlines()
    for line in lines:
        num = line.split(' ',1)[0]
        data = line.split(' ',1)[1]
        data = data.replace('x','0')
        data = data.replace('z','0')
        num = num.replace('000000','')
        num = int(num)//int(4)
        # num = str(num)
        # data = data.replace('\n',', \n') 
        # hex_numm = hex(eval(num)).upper()
        # hex_nummm = hex_numm[2:]
        if (num>int(4000)):
            num = str(num)
            out_file.write(num+','+data)
    in_file.close()
    out_file.close()


if __name__ == '__main__':
    in_file = open("ScanClock","r")
    out_file = open("ScanClock.csv","w")

    file_name1(in_file,out_file)

你可能感兴趣的:(python)