TypeError: unsupported operand type(s) for %: 'int' and 'tuple'
TypeError: unsupported operand type(s) for %: 'int' and 'tuple'
在 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]))
它可以很好地打印消息,但是命令行操作有问题,引用以下错误:
TypeError: unsupported operand type(s) for %: 'int' and 'tuple'
起初,当我这样做时,我使用的是 $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()
调用 returns 一个整数(进程退出代码)。您想要将 %
运算符 应用于字符串参数 ,而不是函数的 return 值。
您正在这样做:
os.system(string) % tuple
而不是
os.system(string % tuple)
移动括号:
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])))
在 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]))
它可以很好地打印消息,但是命令行操作有问题,引用以下错误:
TypeError: unsupported operand type(s) for %: 'int' and 'tuple'
起初,当我这样做时,我使用的是 $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()
调用 returns 一个整数(进程退出代码)。您想要将 %
运算符 应用于字符串参数 ,而不是函数的 return 值。
您正在这样做:
os.system(string) % tuple
而不是
os.system(string % tuple)
移动括号:
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])))