python-argparse-命令行参数

argparse模块使用

# import the necessary packages
import argparse
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-n", "--name", required=True,
	help="name of the user")
args = vars(ap.parse_args())
# display a friendly message to the user
print("Hi there {}, it's nice to meet you!".format(args["name"]))
$ python simple_example.py --help
usage: simple_example.py [-h] -n NAME
optional arguments:
  -h, --help            show this help message and exit
  -n NAME, --name NAME  name of the user

你可能感兴趣的:(python,argparse,命令行参数,python)