argparse

作者: cutelittlePanda | 来源:发表于2017-06-10 19:40 被阅读0次

    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;

    相关文章

      网友评论

          本文标题:argparse

          本文链接:https://www.haomeiwen.com/subject/zarcqxtx.html