修改txt文件内容并重新写入
实现功能:
- 读取txt文件
- 修改文件格式并重新写入
gps_path = '' #txt文件路径
f = open(gps_path)
lines = f.readlines()
list = []
for line in lines:
a = line.split(",")
b = a[0:5]
list.append(b)
print(b)
lines = f.readlines()
f.close()
with open(gps_path, 'w+')as f_out:
for i in list:
s = i[0].zfill(4)
c = float(i[2])
d = float(i[3])
e = float(i[4])
print(c)
if c != -1:
f_out.write(s+' '+str(c)+' '+str(d)+' '+str(e)+'\n')
- gps值异常将写入 -1,-1,-1