我创建了一个像这样的argparser:
parser = argparse.ArgumentParser(description='someDesc')
parser.add_argument(-a,required=true,choices=[x,y,z])
parser.add_argument( ... )
Run Code Online (Sandbox Code Playgroud)
但是,仅用于选择"x"而不用于选择"y,z",我想要一个额外的REQUIRED参数.例如.
python test -a x // not fine...needs additional MANDATORY argument b
python test -a y // fine...will run
python test -a z // fine...will run
python test -a x -b "ccc" // fine...will run
Run Code Online (Sandbox Code Playgroud)
如何使用ArgumentParser实现这一目标?我知道它可能与bash optparser