0

I wrote the following command but I don't understand it.
from sys import argv
what is argv?
how to use it?
I wrote sycript,a,b=argv
but I am getting the error that need more than one value to unpack.

  • 2
    Possible duplicate of [from sys import argv - what is the function of "script"](http://stackoverflow.com/questions/13666346/from-sys-import-argv-what-is-the-function-of-script) – Amndeep7 Jun 02 '16 at 14:07
  • Possible duplicate of [What does 'sys.argv' mean?](http://stackoverflow.com/questions/9455148/what-does-sys-argv-mean) – fuglede Sep 02 '16 at 20:50

2 Answers2

0

argv - The list of command line arguments passed to a Python script.

sycript,a,b=argv gives you "ValueError: need more than 1 value to unpack" because you have just run the script as python <script_name.py> without giving the two arguments.

Run the script like this: python <script_name.py> <arg1> <arg2>

For example,

script.py:

from sys import argv
arg,a,b=argv
print(arg,a,b)

run script.py "arg1" "arg2" and output:

script.py arg1 arg2
Ani Menon
  • 27,209
  • 16
  • 105
  • 126
0

I think you should run the command by typing

python scriptname a b

By scriptname I mean the name by which you have saved the program code.

I hope this helps..

dimodi
  • 3,969
  • 1
  • 13
  • 23