python 不用科学计数&文件转换

#!/usr/bin/python3

import sys;
import io;

fp = open(sys.argv[1], "r")
wfp = open("sensor.txt", "w")

contents=fp.readlines()

for line in contents :
    str=line.split()
    type=str[0]
    if type == 'H' :
        #需要转换的地方
        #timestamp1=str[1]

        tmp5=float(str[5])*3.14159/180.0/1000.0
        tmp6=float(str[6])*3.14159/180.0/1000.0

        tv5="{:.6f}".format(tmp5)
        tv6="{:.6f}".format(tmp6)

        v5=repr(tv5)
        v6=repr(tv6)
        new_line="H " + str[1] + " " + str[2] + " " + str[3] + " " + str[4] + " " + v5 + " " + v6 + " " + str[7] + " " + str[8] + "\n"
        tmp=new_line.replace("'", "");
        print(tmp)
        wfp.writelines(tmp)
    else :
        #不需要转换的地方,直接读取后写入
        wfp.writelines(line)        
        

你可能感兴趣的:(python)