Python parser.add_argument Guide
The parser.add_argument method is a function in the argparse module, used to add command line arguments to an ArgumentParser object.
By using the parser.add_argument method, you can define the name, type, default value, help information, etc. of command-line arguments, so that the user’s input can be correctly parsed when parsing command-line arguments.
For example:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--input", help="input file path")
parser.add_argument("--output", help="output file path")
args = parser.parse_args()
print(args.input)
print(args.output)
In the example above, the parser.add_argument method is used to define two command line arguments –input and –output, and add corresponding help text to them. Finally, by using the parser.parse_args() method, the command line arguments are parsed to retrieve the user input values which can be used for further processing in the program.