python未定义名称大小_名称错误:未定义名称“高度”

我有一个gps代码,可以获取gps数据并写入日志:#!/usr/bin/python

from systemd import journal

import gps

import time

import threading

import datetime

# Listen on port 2947 (gpsd) of localhost

session = gps.gps("localhost", "2947")

session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

while True:

try:

report = session.next() # Wait for a 'TPV' report and display

the current time

# To see all report data, uncomment the line below

#print report

if report['class'] == 'TPV':

if hasattr(report, 'time'):

timestamp = (time.time()*1000)

#print timestamp

if hasattr(report, 'lat'):

latitude = report.lat

#print latitude

if hasattr(report, 'lon'):

longitude = report.lon

#print longitude

if hasattr(report, 'alt'):

altitude = report.alt

#print altitude

else:

timestamp = (time.time()*1000)

latitude = 0

longitude = 0

altitude = 0

journal.send(

channel = 'gps',

priority = journal.Priority.INFO,

timestamp = "%f" % (timestamp),

latitude = "%f" % (latitude),

longitude = "%f" % (longitude),

altitude = "%f" % (altitude),

)

except KeyError:

pass

except KeyboardInterrupt:

quit()

except StopIteration:

session = None

print "GPSD has terminated"

我得到一个错误:

^{pr2}$

有趣的是代码有时工作得很好,有时它会给我这个错误。我不明白我应该怎么做才能让它一直正常工作。这和她爆炸有关吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值