argparse

2017-06-10  本文已影响0人  cutelittlePanda

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 sample code;
上一篇下一篇

猜你喜欢

热点阅读