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")
除了评论中已经提到的错误( hsattr
、 'lat' and 'lon
等),缩进问题是由latitude = report.lat
和以下几行缩进两次引起的。
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.