In python, sys.argv
is a list which contains the command-line
arguments passed to the script.
So for instance you could create a python file named testingArguments.py
which would print the arguments parsed from the command-line
.
The code for this may simply look something like:
from sys import argv
print(argv)
then from the command line, if you ran the command:
python testingArguments.py arg1 arg2 3
then it would print out the arguments in a list
so:
['testingArguments.py', 'arg1', 'arg2', '3']
what your code does, is get this list
in the same way, then unpacks it just like you can a list
not from sys.argv
:
a, b, c, d = [1, 2, 3, 4]
now a=1
, b=2
, c=3
and d=4
.
so hopefully you can see now that altogether, your code just prints out the four arguments passed at the command line which are the script name and 3
more arguments as above.
The error
that you are getting:
ValueError: not enough values to unpack (expected 4, got 1)
is because you are not passing in these 3
extra variable so sys.argv
can't be unpacked into 4
as it only has one element: the script name. Hence the last bit: (expected 4, got 1)
.
Hope this helps!