I am following `learn python 3 the hard way` and in exercise 13 I messed up
Question:
ok I am beginner to python
and in exercise 13 of learn python 3 the hard way
I was not able to make the code work by typing it
so I copied the code and tried to run it but It still did not work
here is the code
from sys import argv
# read the WYSS section for how to run this
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 the error was
Traceback (most recent call last):
File "d:projectsfirstapp.py", line 114, in <module>
script, first, second, third = argv
ValueError: not enough values to unpack (expected 4, got 1)`
(it is on line 114 cuz every code I wrote from this book was commented above)
I thought something was wrong with my python extention or whatever
so i used repl.it and I got the same error
so what do i need to know for running the code?
or the pastebin like is here https://pastebin.ubuntu.com/p/b9kKNbZ5hF/
Answers:
You need to pass in the arguments when calling the program from the command line, the example ‘Learn Python 3 the hard way’ gives is:
$ python ex13.py apple orange grapefruit
Where the script is called with 3 arguments and the resulting output of the code is:
The script is called: ex13.py
Your first variable is: apple
Your second variable is: orange
Your third variable is: grapefruit
In fact, if you had read further in the chapter, you would see that they discuss the exact error that you posted and the reason why it ocurrs
I wish I would have seen this about two and a half years ago. it took me about 30-40 minutes but I figured it out. You have to call each variable when you run this file. I added a fourth and a fifth line and that’s how I eventually figured it out, because I called the file just as the example in the What You Should See section showed me: python ex13.py first 2nd 3rd
It was then that it showed me how to call it properly which was to call the file like this: python ex13.py first 2nd 3rd 4th 5th
resulting in:
python ex13.py first 2nd 3rd 4th 5th
The script is called: ex13.py
Your first variable is: first
Your second variable is: 2nd
Your third variable is: 3rd
Your fourth variable is: 4th
Your fifth variable is: 5th
I could have looked ahead to the Common Student Questions section but I prefer to work things out and figure it out without a lot of clues. It teaches me to find solutions before asking for the easy answers.
ok I am beginner to python
and in exercise 13 of learn python 3 the hard way
I was not able to make the code work by typing it
so I copied the code and tried to run it but It still did not work
here is the code
from sys import argv
# read the WYSS section for how to run this
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 the error was
Traceback (most recent call last):
File "d:projectsfirstapp.py", line 114, in <module>
script, first, second, third = argv
ValueError: not enough values to unpack (expected 4, got 1)`
(it is on line 114 cuz every code I wrote from this book was commented above)
I thought something was wrong with my python extention or whatever
so i used repl.it and I got the same error
so what do i need to know for running the code?
or the pastebin like is here https://pastebin.ubuntu.com/p/b9kKNbZ5hF/
You need to pass in the arguments when calling the program from the command line, the example ‘Learn Python 3 the hard way’ gives is:
$ python ex13.py apple orange grapefruit
Where the script is called with 3 arguments and the resulting output of the code is:
The script is called: ex13.py
Your first variable is: apple
Your second variable is: orange
Your third variable is: grapefruit
In fact, if you had read further in the chapter, you would see that they discuss the exact error that you posted and the reason why it ocurrs
I wish I would have seen this about two and a half years ago. it took me about 30-40 minutes but I figured it out. You have to call each variable when you run this file. I added a fourth and a fifth line and that’s how I eventually figured it out, because I called the file just as the example in the What You Should See section showed me: python ex13.py first 2nd 3rd
It was then that it showed me how to call it properly which was to call the file like this: python ex13.py first 2nd 3rd 4th 5th
resulting in:
python ex13.py first 2nd 3rd 4th 5th
The script is called: ex13.py
Your first variable is: first
Your second variable is: 2nd
Your third variable is: 3rd
Your fourth variable is: 4th
Your fifth variable is: 5th
I could have looked ahead to the Common Student Questions section but I prefer to work things out and figure it out without a lot of clues. It teaches me to find solutions before asking for the easy answers.