在我之前的question之后。有人建议我创建一个单独的python库,然后导入它。在
在阅读了更多关于Stackoverflow
的文章后,我意识到最好的方法是write methods,我选择了这个方法。在
def USB(port):
activateme = serial.Serial(port,115200)
#print "starting to monitor"
for line in activateme:
#print line
return line
def USBprocess(line):
if line.startswith( '#d'):
fields = line.split(',')
if len(fields) > 5:
W = fields[1]
V = fields[2]
A = fields[3]
print "monitoring"
return W,V,A
op = USB(port)
w,v,a = USBprocess(op)
我得到了一个错误:
^{pr2}$我做错什么了?在
您应该在函数的开头为}。可能是这样(根据您的问题更改默认值):
W, V, A
提供值,以防第一个if
条件不是{如果此表达式不正确:
变量}不会在
W
、V
和{USBprocess
函数中初始化,因此return
将失败。在通过在
if
语句之前初始化所有局部变量来修复它。在相关问题 更多 >
编程相关推荐