Python Command Line Arguments Guide
In Python, you can use sys.argv to access command-line arguments. sys.argv is a list containing the command-line arguments, with the first element being the name of the script file, and the subsequent elements being each parameter passed to the script.
Here is a sample code demonstrating how to retrieve command line arguments and print them out:
import sys
# 获取命令行参数
arguments = sys.argv
# 打印命令行参数
for arg in arguments:
print(arg)
For example, if you run the python script.py with arguments arg1, arg2, and arg3, the above code will output:
script.py
arg1
arg2
arg3