How to use raw_input with argv?

I am making ex13 from Learn Python The Hard Way

I am 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 am 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 get this error and how to fix it.

+4
source share
10 answers

You cannot use raw_input()with argv". argvComes with the data that you specify before starting the program. raw_input()Is a Python function, that is, something your program can do. The command line in which you enter the command pythonto start your program is completely separate thing from the program itself.

+7
source

LPTHW . , , , , script, argv, raw_input(). , , , - . , " ", , .

. script, raw_input(), -, . script.

, 2 , , .

script, "Study Drill":

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)
+8

13 Learn Python Hard Way, argv raw_input(). raw_input() .

:

from sys import argv

ScriptName, first, second, third = argv

print "What is your fourth variable?"
fourth = raw_input()
print "What is your fifth variable?"
fifth = raw_input()
print "What is your sixth variable?"
sixth = raw_input()

print "The script is called: ", ScriptName
print "Your first variable is: ", first
print "Your second variable is: ", second
print "Your third variable is: ", third
print "Your fourth variable is: ", fourth
print "Your fifth variable is: ", fifth
print "Your sixth variable is: ", sixth

print "For your script %r, these are the variables: %r, %r, %r, %r, %r,
    and %r." % (ScriptName, first, second, third, fourth, fifth, sixth)

, ?

+2

, , ( argv int raw_input()): -

from sys import argv

script, first, second, third, take_input = 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

raw_input(take_input + "? ")
0

: " raw_input argv, script, .", .

fourth = raw_input("Enter the fourth value: ")    
print "Your fourth variable is: ", fourth    

, , , , " script, ",

from sys import argv

script, first, second, third = argv, raw_input("Enter first value: "), raw_input("Enter second value: "), raw_input("Enter third value: ")

print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third

python ex13.py script. , , , , .

0

, , , .

argv [] ( ), script.

:

from sys import argv
script, first, second, third = argv # one way to unpack the arguments

script_new = argv[0] # another way
first_new = argv[1]
second_new = argv[2]
third_new = argv[3]

print "original unpacking: ", script, first, second, third
print "argv[] unpacking: ",script_new, first_new, second_new, third_new

argv[0] = raw_input("argument 0? ")
argv[1] = raw_input("argument 1? ")
argv[2] = raw_input("argument 2? ")
argv[3] = raw_input("argument 3? ")

print argv[0], argv[1], argv[2], argv[3]
0

, , , . :

from sys import argv

script, slave = argv
print "Superme master, slave %s is waiting for your order." % slave

slave_says = "Humble %s wants know your supreme name, master:\n" % slave
name = raw_input(slave_says)

want = raw_input("What do you want, my superme master?\n")
if want == "Make you freedom.":
    print "When you make me freedom. you are also make yourself freedom."
else:
    print "Yes, my superme master."
0

enter image description here , , . , raw_input(), .

argv raw_input()

enter image description here

0

" " , argv .

, argv ( python ex13.py raw_input() raw_input() raw_input() - ), , .

-1

: ipython

% run ex13.py 1st 2nd 3rd

 python ex13.py 1st 2nd 3rd
-1
source

All Articles