1

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

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.