sed174
sed174

Reputation: 133

ValueError: not enough values to unpack (expected 4, got 1)

The error is at script, first, second, third = argv. I would like to understand why I am getting the error and how to fix it.

from sys import argv

script, first, second, third = argv
print("The script is called: ", script)
print("The first variable is: ", first)
print("The second variable is: ", second)
print("The third variable is: ", third)

Upvotes: 13

Views: 76638

Answers (4)

Ashutosh Singla
Ashutosh Singla

Reputation: 739

I think you are running the following command:

python script.py

You are writing a program which is aksing for 4 inputs and you are giving onle one. That's why you are receiving an error. You can use the below command:

python script.py Hello How Are

Upvotes: 0

user3900428
user3900428

Reputation: 1

You could run it like this: python script.py first, second, third

Upvotes: 0

kvorobiev
kvorobiev

Reputation: 5070

argv variable contains command line arguments. In your code you expected 4 arguments, but got only 1 (first argument always script name). You could configure arguments in pycharm. Go to Run -> Edit Configurations. Then create a new python configuration. And there you could specify Script parameters field. Or you could run your script from command line as mentioned by dnit13.

Upvotes: 3

dnit13
dnit13

Reputation: 2496

Run it from the shell like this:

python script.py arg1 arg2 arg3

Upvotes: 5

Related Questions