python of sys.argv, get command line arguments

Preface:

  When designing code, scripts will use a lot of command line arguments, as to certain parameters. Often see others used: python3 test.py -h, then print out a bunch of helpful information. Or for other processing. Learning a method sys.argv here

sys.argv is actually a list of items inside for user input parameters, these parameters are input from the external program

Simply look at an example:

import sys
print(sys.argv)

Then he went to the command line:

 

We executed by the map, print a function name, a list type, then it looks like we'll be like any other parameters plus about it

 

We got a number of parameters, to where it should all be relatively clear.

 

That someone will ask me in front of the file add parameters? try it

 

Here I added a -s, printed above content, which tells us that this is for the python3 -s, so here it is quite clear the bar.

 

in conclusion:

sys.argv return value is a list type

Sys.argv value of 0 is the file itself

sys.argv in order to add to a list

Guess you like

Origin www.cnblogs.com/dflblog/p/12050060.html