The answer is yes . A quick response to the documentation argparse would also respond.
Here is a very simple example: argparse is capable of handling much more specific needs.
import argparse parser = argparse.ArgumentParser() parser.add_argument('--foo', '-f', help="a random options", type= str) parser.add_argument('--bar', '-b', help="a more random option", type= int, default= 0) print(parser.format_help())
Off-course, in a real script, you will not hard-code command-line options and instead call parser.parse_args() (without an argument). It will force argparse to take the sys.args list as command line arguments.
You can call this script as follows:
test_args_4.py -h # prints the help message test_args_4.py -f pouet # foo="pouet", bar=0 (default value) test_args_4.py -b 42 # foo=None, bar=42 test_args_4.py -b 77 -f knock # foo="knock", bar=77
You will discover many other functions by reading the document;)
Tryph
source share