1

Hey guys I was trying to use the argument variable in Python however am unable to execute the program at the terminal.

Program:

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

Output:

>>> execfile("lesson13.py","dog","cat")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be dict, not str
>>> 
chepner
  • 497,756
  • 71
  • 530
  • 681
user1345589
  • 61
  • 1
  • 2
  • 7
  • The error has nothing to do with the program, you just misuse `execfile`. –  Apr 21 '12 at 18:04

1 Answers1

4

execfile() doesn't take command arguments. Try using subprocess instead.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • Here is a SE question for the same issue: http://stackoverflow.com/questions/5788891/execfile-with-argument-in-python-shell – CppLearner Apr 21 '12 at 18:13
  • >>> subprocess.call('lesson13.py','kill','bill','kim') Traceback (most recent call last): File "", line 1, in NameError: name 'subprocess' is not defined – user1345589 Apr 22 '12 at 11:41
  • `subprocess is not defined` Did you import it? Update your post if you still can't resolve! – CppLearner Apr 23 '12 at 21:12