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')
div>
Read More:
- The function and usage of argc and argv in C language
- Error in installing pywin32 under Windows: close failed in file object D estructor:sys.excepthook is missing lost sys.stderr
- The usage of typing.union in Python
- Yield usage in Python
- Python error unhandled exception in thread started by error in sys.excepthook
- Usage of Python dropout
- Python program exit: OS_ Exit() and sys.exit ()
- Solve the syntax error of Python PIP installation sys.stderr.write (f“ERROR: {exc}“)
- Raise in Oracle_APPLICATION_Error Usage
- Usage of pause function in MATLAB
- Import sys module
- Usage of NVL in SQL
- The usage and difference of atoi() and stoi() functions in C + +
- svn Key usage violation in certificate has been detected
- Usage and examples of three important functions of tidyr package in R language: gather, spread and separate
- JS exception capture: the usage and example analysis of onerror() in window
- The usage of several integer functions in MATLAB (fix, floor, ceil, round)
- Python – [encoding] in Python os.system Solution to Chinese garbled code when calling CMD command
- Solve the problem of unable to locate package python3.6 when upgrading from python3.5 to python3.6 in ubantu16.04
- On the usage of ‘ref.stor.type search’ field in SAP WM movement type