2012-04-21 110 views
1

嘿家伙我试图在Python中使用参数变量,但无法在终端执行程序。TypeError:必须是字典,而不是str

计划:

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 
>>> 
+0

该错误与程序无关,您只是误用了'execfile'。 – delnan 2012-04-21 18:04:05

回答

4

execfile()不带命令的参数。请尝试使用subprocess

+0

下面是同一个问题的SE问题:http://stackoverflow.com/questions/5788891/execfile-with-argument-in-python-shell – CppLearner 2012-04-21 18:13:08

+0

>>> subprocess.call('lesson13.py','kill ”,‘比尔’,‘金’) 回溯(最近通话最后一个): 文件‘’,1号线,在 NameError:名字‘子’没有定义 – user1345589 2012-04-22 11:41:58

+0

我仍然无法得到它的工作:( – user1345589 2012-04-22 11:42:17

相关问题