What is “argv”, and what does it do?

前端 未结 7 1691
耶瑟儿~
耶瑟儿~ 2020-11-30 04:36

argv

What on Earth is it!?

Edit: If you can, will you please write a line or two and explain how it works?

7条回答
  •  旧时难觅i
    2020-11-30 04:46

    If you have an executable python script and call it with arguments like this:

    myscript.py -a -b --input myfile --another_argument
    

    then sys.argv is a list containing:

    ['myscript.py', '-a', '-b', '--input', 'myfile', '--another_argument']
    

    Using it is the only way to access these arguments, and that is its main use. However, most applications use libraries such as the argparse module to access this information without needing to use sys.argv directly.

提交回复
热议问题