在一个Raspberry Pi上,我设置了它,以便它监视来自用户的ASCII串行输入,然后它解析并用解析的数据填充一个矩阵。但当我试图处理数据时:
for i in range(1,7):
if matrixA[i][1]>0:
print "sending DO_Fire (pin %d) HIGH for %dms, with a power level of %d"%(DO_Fire,int(matrixA[i][1]),int(matrixA[i][2]))
os.system("pigs m %d w wvclr wvag 16 0 %d 0 16 10000 wvcre")%(DO_Fire,int(matrixA[i][1]))
os.system("pigs m %d w wvag 0 16 %d 16 0 10000 wvcre wvtx 0")%(LED_Fire,int(matrixA[i][2]))
它可以很好地打印消息,但在命令行操作中出现问题,原因是以下错误:
^{pr2}$一开始我这么做的时候,我使用的是$s
,所以我想我只需要将数据转换为int
,但这并没有任何区别。在
我错过了什么?如有任何建议或有用的意见,我们将不胜感激。在
根据要求,在下面进行全面追溯:
Traceback (most recent call last):
File "rs232.py", line 974, in <module>
line = readLine(ser)
File "rs232.py", line 131, in readLine
goA()
File "rs232.py", line 184, in goA
preheats() #detect all stored preheats and fire them
File "rs232.py", line 147, in preheats
os.system("pigs m %d w wvclr wvag 16 0 %d 0 16 10000 wvcre")%(DO_Fire,int(matrixA[i][1]))
TypeError: unsupported operand type(s) for %: 'int' and 'tuple'
os.system()
调用返回一个整数(进程退出代码)。您希望将%
运算符应用于字符串参数,而不是函数的返回值。在你要做的是:
而不是
^{pr2}$移动括号:
相关问题 更多 >
编程相关推荐