I am using a Macbook Pro, running OS X Yosemite 10.10.4, and was going through the exercises in Learn Python the Hard Way. I'm running these on iPython notebooks, and their config is as below:
Python 2.7.10 |Anaconda 2.2.0 (x86_64)| (default, May 28 2015, 17:04:42) [GCC 4.2.1 (Apple Inc. build 5577)]
On Ex13, listed on http://learnpythonthehardway.org/book/ex13.html I typed and/or copied the exact code on the site but got an error.
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
On running the above code, the error message I receive is this:
ValueError Traceback (most recent call last) in () ----> 1 script, first, second, third = argv
ValueError: too many values to unpack
I tried running the code line by line, and found that the problem is when I'm assigning more than one value to argv. For example, the code below executes fully.
from sys import argv
script = argv
print "The script is called:", script
The output for the above code is:
The script is called: ['/Users/myusername/anaconda/lib/python2.7/site-packages/IPython/kernel/main.py', '-f', '/Users/myusername/.ipython/profile_default/security/kernel-261810c2-9f04-44d4-95f7-411e0db361ff.json', '--profile-dir', '/Users/myusername/.ipython/profile_default']
What could be the possible reasons for this, and how could I go about rectifying it?
Update:
I tried running this via terminal as suggested, and this was the response I received.

print(len(argv))before your tuple unpakcing and see what the results from that are. If that's anything other than 4 you will have problems. The second code snippet will print the entireargvregardless of the number of parameters and hence not be a problem. - shuttle87Invokeyour script from terminal (not python terminal) , command line terminal. (and don't write your code there) , first save it as a script and then invoke that script. - Anand S Kumar