In Python sys.argv Usage of

Argv is the command line parameter

that you get when you run a python file

the following code file is a.py, when I am not using the IDE tool, only the command line window to run, go to the directory where the file is, input: python a py output results as follows

import sys
a=sys.argv
b=len(sys.argv)
print(a)
print(b)

输出:
['a.py']
1

is the same code as above, when I run it, input: python a. zhang output:

['a.py', 'zhang']
2

continue running input: python a.p zhang kang output:

['a.py', 'zhang', 'kang']
3
, I don’t have to tell you that you get it. Now get the input parameter values:
python a. zhang kang

#encoding=utf-8
import sys
a=sys.argv[0]
b=sys.argv[1]
c=sys.argv[2]
print("filename:",a)
print("param1:",b)
print("param2:",c)

输出:
('filename:', 'a.py')
('param1:', 'zhang')
('param2:', 'kang')

Read More: