Zack Shapiro Zack Shapiro - 1 year ago 89
Python Question

Using command line arguments in Python: Understanding sys.argv

I'm currently going through Learn Python The Hard Way. I think this example might be out dated so I wanted to get feedback here on it.

I'm using Python 3.1

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

I'm getting this error:

Traceback (most recent call last):
File "/path/", line 3, in <module>
script, first, second, third, bacon = argv
ValueError: need more than 1 value to unpack

Any idea what's wrong?

Answer Source

You forgot to pass arguments to the script, e.g. bar baz quux.

enter image description here