Python Forum
Putting GPS data into a file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Putting GPS data into a file (/thread-3491.html)



Putting GPS data into a file - kendias - May-28-2017

my question here
I am trying to input data that streams from a GPS module into a file. The file locations.csv opens OK but stays blank with no data input into the file!

from gps import *
import time
import threading
f = open("locations.csv","w")
gpsd = None
class GpsPoller(threading.Thread):
   def __init__(self):
       threading.Thread.__init__(self)
       global gpsd
       gpsd=gps(mode=WATCH_ENABLE)
       self.current_value = None
       self.running = True
   def run(self):
       global gpsd
       while gpsp.running:
           gpsd.next()
if  __name__ == '__main__':
   gpsp=GpsPoller()
   try:
       gpsp.start()
       while True:
           f.write(str(gpsd.fix.longitude) + ',' + str(gpsd.fix.latitude) + "\n")
           time.sleep(30)
   except(KeyboardInterrupt,SystemExit):
       f.close()
       gpsp.running = False
       gpsp.join()