来自python的外部命令

2024-06-16 15:07:03 发布

您现在位置:Python中文网/ 问答频道 /正文

def OnClick(self,event):
    print "a:", a
    os.system('iperf -s -w a')

此处a正确显示。但是在os.system命令中,a的值取0。 你能帮我一下吗?在


Tags: 命令selfeventosdefsystemprintiperf
2条回答
os.system('iperf -s -w a')

接受文字a而不是变量的值。我会用:

^{pr2}$

参考input output formatting in python

您并没有传递a的值,而是按原样传递a。所以,你可能想这么做

os.system('iperf -s -w {}'.format(a))

现在,a的值将被替换为{}。通过打印,可以看出两个版本之间的区别

^{pr2}$

相关问题 更多 >