from sys income argvscript, user_name =argvprompt = ">"print "Hi %s, I"m the %s script." % (user_name, script)I acquire this error:

Traceback (most recent contact last): script, user_name =argv ValueError: need more than 1 value to unpackWhat does that error mean?


*

*

Probably you didn"t administer an dispute on the command line. In that case, sys.argv only has one value, but it would need to have 2 in order to administer values for both user_name and also script.

You are watching: Valueerror: need more than 1 value to unpack


*

youre getting ""ValueError: need much more than 1 worth to unpack"", because you only offered one value, the script (which is ex14.py in this case)

the difficulty is, the you forgot to add a name after you ran the .py file.

line 3 of your password is

script, user_name = argvthe script is ex14.py, girlfriend forgot to add a surname after

so if your name to be michael,so what you get in into the terminal have to look miscellaneous like:

> python ex14.py michaelmake this change and the code runs perfectly


*

You can"t operation this specific piece of code in the interaction interpreter.You"ll should save it right into a file first so that you have the right to pass the argument to it like this

$ python hello.py user338690

*

You shouldn"t it is in doing tuple dereferencing on worths that can readjust like your line below.

script, user_name = argvThe line over will failure if friend pass less than one debate or an ext than one argument. A better way of doing this is to perform something like this:

for arg in argv<1:>: publish argOf cause you will perform something other than publish the args. Possibly put a series of "if" statement in the "for" loop that collection variables depending upon the debates passed. One even better way is to usage the getopt or optparse packages.


You have to pass the arguments in the terminal in order to store them in "argv". This change holds the debates you happen to her Python script once you run it. It later unpacks the arguments and store castle in different variables you specify in the regime e.g.

script, first, 2nd = argvprint "Your paper is:", scriptprint "Your very first entry is:", firstprint "Your second entry is:" secondThen in your command heat you have to run her code like this,

$python ex14.py Hamburger PizzaYour output will look favor this:

Your record is: ex14.pyYour very first entry is: HamburgerYour second entry is: Pizza
You need to run your code in a following manner in order obtain your output,

python file_name.py user_name
I assume you found this code on practice 14: Prompting and Passing.

Do the following:

script = "*some arguments*" user_name = "*some arguments*"and that works perfectly


This error is since

argv # which is discussion variable that is holding the variables the you pass through a speak to to the script.

so now rather

Python abc.py

do

python abc.py yourname pass the variable that you make to keep argv


Thanks for contributing an answer to ridge Overflow!

Please be certain to answer the question. Carry out details and also share her research!

But avoid

Asking because that help, clarification, or responding to various other answers.Making statements based upon opinion; back them up with recommendations or an individual experience.

See more: Riddle: What Has A Head A Tail Is Brown And Has No Legs ? Head And Tail

To discover more, watch our advice on writing an excellent answers.


short article Your answer Discard

By click “Post your Answer”, friend agree to our regards to service, privacy policy and also cookie plan


Not the prize you're looking for? Browse various other questions tagged python debates or questioning your very own question.


UnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position 20: ordinal no in range(128)
site design / logo design © 2021 ridge Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.10.27.40585


her privacy

By clicking “Accept every cookies”, friend agree ridge Exchange deserve to store cookie on your an equipment and disclose details in accordance v our Cookie Policy.