How to use raw_input with argv?

J A picture J A · Sep 4, 2014 · Viewed 11.7k times · Source

I'm doing ex13 from Learn Python The Hard Way

I'm trying to pass:

python ex13.py raw_input() raw_input() raw_input()

my code is below:

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

The error I keep getting is:

Traceback (most recent call last):
 File "ex13.py", line 5, in <module>
   script, first, second, third = argv
ValueError: too many values to unpack

I want to know why i'm getting this error and how to fix it

Answer

user3960721 picture user3960721 · Nov 23, 2014

I'm currently going through LPTHW myself and just got to this exercise. I think what the author means is that he wants you to, just in the same script, use both argv and raw_input(). He doesn't mean for you to combine them, per se, in the same argument or line or whatever. In fact, one of the 'Common Student Questions' that he mentions deals with just this problem. He says

Don't overthink it. Just slap two lines at the end of this script that uses raw_input() to get something and then print it. From that start playing with more ways to use both in the same script.

Even though it's 2 months late, hope it helps.

This is how I've modified the script in order to complete the 'Study Drill' in question:

from sys import argv

script, first, second, third = argv
fourth = raw_input("What is your fourth variable? ")

print "All together, your script is called %r, your first variable is %r, your second is %r, your third is %r, and your fourth is %r" % (script, first, second, third, fourth)