Question

No matter how many times I indent my code, I keep getting this error. I even added exception handling and it still errors out.

import gps 
import os

session=gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE|gps.WATCH_NEWSTYLE)

while True:
      try:

            report = session.next()
            if report['class'] == 'TPV':
                if hsattr(report,'lat' and 'lon'):
                        latitude  = report.lat
                        latString = "lat:%f" % (latitude)
                        longitude = report.lon
                        longString = "lon:%f" % (longitude)
                        f = open("gsp.txt", "w")
                        f.write("%s,%s" %(latString,lonString))
                        f.close()
                        #os.system("java -jar gps.jar")
Was it helpful?

Solution

Besides the errors already mentioned in the comments (hsattr, 'lat' and 'lon, etc), the indentation problem arises from latitude = report.lat and the following lines being indented twice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top