Python TypeError:不支持%的操作数类型:';int';和';元组';

Python TypeError:不支持%的操作数类型:';int';和';元组';,python,formatting,raspberry-pi,Python,Formatting,Raspberry Pi,在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

在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'
回溯(最近一次呼叫最后一次):
文件“rs232.py”,第974行,在
行=读行(ser)
readLine中第131行的文件“rs232.py”
果阿()
文件“rs232.py”,第184行,果阿
预热()#检测所有储存的预热并点火
文件“rs232.py”,第147行,在预热中
操作系统(“清管器m%d w wvclr wvag 16 0%d 0 16 10000 wvcre”)%(内部点火(矩阵[i][1]))
TypeError:不支持%:“int”和“tuple”的操作数类型
调用
os.system()
返回一个整数(进程退出代码)。您希望将
%
运算符应用于字符串参数,而不是函数的返回值

您正在这样做:

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])))

哪一行引起错误?发布完整回溯。您正在使用
%d
将元组格式化为整数。括号错误-您试图格式化
os.system
的返回值,它是一个整数,而不是它的参数。
os.system(“pigs m%d w wvclr wvag 16 0%d 0 16 10000 wvcre”)%(DO_Fire,int(matrixA[i][1])
之后的行将尝试在
os.system()的结果上使用“%”。对于这一行和后面的那一行,您需要括号位于
%
表达式之外。感谢您的输入,各位!Martijn用正确的括号把我弄清楚了。谢谢Martijn,这就成功了。非常感谢!