I've collected the GPS position data of my day into a txt file. There are N lines about my data. And there are 5 fields in one line(latitude, longitude, altitude, date, time). I want to use python read that. This is my code(There is no problem in this code).
#open file
f = open("path",'r')
#read lines
lines = f.read()
print(lines)
#close files
f.close()
How can I read it like latitude, longitude or date, time? I just want one of the data in one line.
Assuming the fields are split by commas you could do something like this
with open("path", "r") as file:
for line in file.readlines():
latitude, longitude, altitude, date, time = line.split(",")
do_something(latitude, longitude, altitude, date, time)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.