简体   繁体   中英

Parameters, Unpacking and variables - Learn python the hard way ex 13

I'm stuck at this point. here is the code:

from sys import argv

script, first, second, third = argv

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

my problem is this, when I run it I get:

value error need more than one value to unpack

as far as I can see I have three values and the code is good, could someone explain where I am going wrong please.

So, in chat @Ricky troubleshooted his way to successfully determining that argv was splitting on whitespace and not , comma . Changing his command line params from

$python myprog.py one,two,three

to

$python myprog.py one two three

made everything fine.

For those who wish to learn the mysteries of the argparse .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM