I am trying to run a python script passing arguments in the command line. The way I am doing is the following:
from sys import argv
x, y = argv
When I try to run the script:
./tst.py 23 1421 (the integers being the arguments)
I get encounter the following error:
ValueError: too many values to unpack
I am ultimately converting this script as a binary using pyinstaller and the executable would be called from any external application (for eg: Java code).
Any help would be much appreciated on this particular issue and any better method of passing argument to the binary ultimately.
1 Answer 1
sys.argv includes the script name, so you have three values in the list, not two.
Take that into account when unpacking; either ignore the first element:
x, v = sys.argv[1:]
or include another target:
script, x, v = sys.argv
From the sys.argv documentation:
The list of command line arguments passed to a Python script.
argv[0]is the script name (it is operating system dependent whether this is a full pathname or not).