argparse

import argparse

parser = ArgumentParser(prog="myprogram",  description = "the detailed information for this .py file")

parser.add_argument('-v', '--verbose', help="print out the detailed information if specified", action='store_true' )

parser.add_argument('-q', '-quiet', help="print as less as info out", action='store_true')

parser.add_argument('-n', '--num', help="numbers inputed", nargs='+')

parser.print_help()

args = parser.parse_args()

print("The Namespace:   ", args, sep='\n')

if args.verbose:

           print("the detailed infomation blablablabla .........blablablabla")

elif args.quiet:

            print("as less as info")

else:

            print("the default")

...........

argparse_第1张图片
argparse sample code;

你可能感兴趣的:(argparse)