Jun-06-2017, 06:53 PM
Thanks.
No output after removing comments from script in my previous post but do get output from script below. It prints lat, lon but into the python shell i.e. print works but f.write does not work.
No output after removing comments from script in my previous post but do get output from script below. It prints lat, lon but into the python shell i.e. print works but f.write does not work.
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() print (gpsd.fix.longitude) print (gpsd.fix.latitude) 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()