1

I'm practicing Python with the book called Learn "Python The Hard Way 3rd edition". I searched that this book is a good resource to get a start.

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)

And I got an error saying that value error: not enough values to unpack (expected 4, got 1).

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Oliver Bird
  • 145
  • 2
  • 15

2 Answers2

2

You need to run the script with three arguments, so that argv contains four elements (the first is the script's name).

Mureinik
  • 297,002
  • 52
  • 306
  • 350
1

argv is a list containing the following: argv[0] is the script pathname if known argv[1], argv[2], argv[3]... contains arguments passed from the shell.

In order for your code to work you need to run it with 3 arguments so that they can be unpacked and assigned to your 4 variables.