How do I create a Python namespace (argparse.parse_args value)?

前端 未结 3 829
终归单人心
终归单人心 2020-12-04 15:18

To interactively test my python script, I would like to create a Namespace object, similar to what would be returned by argparse.parse_args(). The

3条回答
  •  春和景丽
    2020-12-04 15:59

    argparse documentation show various examples of what you're trying to do:

    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("-a")
    parser.parse_args(['-a 12'])
    >>> Namespace(a=' 12')
    

提交回复
热议问题