Disclaimer: I have read the thread located at Python Error: "ValueError: need more than 1 value to unpack", and none of the answers explained how to actually get the code to run.
I am reading Learn Python the Hard Way, and I am on Exercise 13.
Here is the code I am attempting to run in the IDLE thing (don't know what it is really called) for Python 2.7:
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
When run, I get the error:
"Traceback (most recent call last):
File "C:PythonLPTHWexamples_LPTHWex13.py", line 3, in
script, first, second, third = argv
ValueError: need more than 1 value to unpack"
I have tried running the program through the Windows command prompt, to no avail. I have also run the program by typing: "python ex13.py first 2nd 3rd", in both the IDLE and the command prompt, also got the same error.
How do I get this code to run, and what the heck am I doing wrong?
EDIT: @John Machin, I made a program exactly like the one you posted, saved it as a .py, then went into the correct directory where my file was saved, ran the program using "python yourcode.py B C D" and I received the following message "python is not recognized as an internal or external command..." When I run the program by just typing it's name (which works for all other programs besides this one) I get an error saying "SyntaxError: invalid syntax on line 2: print len(argv), repr(argv)".
EDIT 2 (With the new code): @John Machin, I copied your program word for word into gedit and made the .py file as usual. I opened my terminal (command prompt) and typed:
python ex13c.py B C D
And received:
'python' is not recognized as an internal or external command, operable program or batch file."
Then I typed:
ex13c.py
And received:
3.1.3 (r313:86834, Nov 27 2010, 18:30:53) [MSC v.1500 32 bit (Intel)]
1 ['C:\Python\LPTHW\examples_LPTHW\ex13c.py']
Traceback (most recent call last):
File "C:PythonLPTHWexamples_LPTHWex13c.py". line 4, in (module)
a, b, c, d = argv
ValueError: need more than 1 value to unpack
Keep in mind I am running W7 64bit, and that Zed is teaching in 2.X and I have been using 2.7 the entire book so far. Every other example has worked. Right before I started Example 11, I installed 3.1 for a different book I am about to start reading. Every time I use the IDLE included with 2.7. Perhaps it is possible I am somehow inadvertently using 3.1 while trying to code in 2.7?
Thanks for bearing with me.
See Question&Answers more detail:
os