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

前端 未结 7 1689
耶瑟儿~
耶瑟儿~ 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条回答
  •  悲&欢浪女
    2020-11-30 04:58

    You can run python program with or without arguments. If you use arguments they are inside argv vector. For example

    PYTHON PROGRAM!!!

    #!/usr/bin/python
    
    import sys
    
    print 'Number of arguments:', len(sys.argv), 'arguments.'
    print 'Argument List:', str(sys.argv)
    

    RUN SCRIPT LIKE THIS

    $ python test.py arg1 arg2 arg3
    

    AND RESULT IS

    Number of arguments: 4 arguments.
    Argument List: ['test.py', 'arg1', 'arg2', 'arg3']
    

    examples are from tutorialspoint

提交回复
热议问题