1

嘿伙计们,我试图在 Python 中使用参数变量,但是无法在终端上执行程序。

程序:

from sys import argv

script,first,second,third = argv

print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second 
print "Your third variable is:", third

输出:

>>> execfile("lesson13.py","dog","cat")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be dict, not str
>>> 
4

1 回答 1

4

execfile()不接受命令参数。尝试subprocess改用。

于 2012-04-21T18:03:16.363 回答