Python argparse optional sub-arguments

后端 未结 4 1613
温柔的废话
温柔的废话 2020-12-17 17:09

I\'d like to have an argument to my program that has some required parameters along with some optional parameters. Something like this:

[--print text [color          


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 18:06

    that will work for single arg:

    parser.add_argument('--write_google', nargs='?', const='Yes',
                        choices=['force', 'Yes'],
                        help="write local changes to google")
    

提交回复
热议问题