Python Forum
ValueError: not enough values to unpack (expected 4, got 1)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: not enough values to unpack (expected 4, got 1)
#1
while trying to execute the program I got the error mention in the subject.
kindly help me in this, I am new to argv concept
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)
Error:
script, first, second, third = argv ValueError: not enough values to unpack (expected 4, got 1)
Reply
#2
you are expecting four arguments (including the script name, thus 3 additional) on the command where you call the script.
you are only getting the script name, thus the other three arguments haven't been supplied in your run command.
example (with your script named myscript.py):

$ python myscript.py opt1 opt2 opt3
Output:
The script is called: myscript.py your first variable is opt1 your second variable is opt2 your third variable is opt3
BashBedlam likes this post
Reply
#3
I would start with this:
from sys import argv
print(argv)
What gets printed? Try running your program with different command line arguments until you understand how argv works.
ndc85430 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Too much values to unpack actualpy 3 409 Feb-11-2024, 05:38 PM
Last Post: deanhystad
  ValueError - Formatting issue when values enter thousands phillyfa 4 1,113 Apr-20-2023, 06:22 PM
Last Post: phillyfa
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,013 May-17-2022, 11:38 AM
Last Post: Larz60+
  unpack dict menator01 1 1,158 Apr-09-2022, 03:10 PM
Last Post: menator01
  [SOLVED] [geopy] "ValueError: too many values to unpack (expected 2)" Winfried 2 2,835 Mar-30-2021, 07:01 PM
Last Post: Winfried
  Cannot unpack non-iterable NoneType object, i would like to ask for help on this. Jadiac 3 8,818 Oct-18-2020, 02:11 PM
Last Post: Jadiac
  subprogram issues: cannot unpack non-iterable function object error djwilson0495 13 5,865 Aug-20-2020, 05:53 PM
Last Post: deanhystad
  struct.unpack failed Roro 2 3,279 Jun-13-2020, 05:28 PM
Last Post: DreamingInsanity
  Can't unpack values of dictionary with ** Snake 3 3,502 Mar-11-2020, 11:17 AM
Last Post: Snake
  Error: too many values to unpack Mike 1 5,096 Oct-30-2019, 03:07 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020