我有Python中的下面的代码:argparse参数筑巢
parser = argparse.ArgumentParser(description='Deployment tool')
group = parser.add_mutually_exclusive_group()
group.add_argument('-a', '--add', dest='name_to_add', help='Add a new group or a role to existing group')
group.add_argument('-u', '--upgrade', dest='name_to_upgrade', help='Upgrade a group with the new version')
parser.add_argument('--web_port', help='Port of the WEB instance that is being added to the group')
我的问题是 “--web_port” 选项。我想只能用“-a”选项添加此选项,但不能用“-u”添加。
我想要能够运行:“python my_script.py -a名称--web_port = XXXX”。
我不想能够运行:“蟒蛇my_script.py -u名--web_port = XXXX”
我应该如何改变我的代码,以便能够运行这个办法?
谢谢,Arshavski亚历山大。
[python,argparse:启用输入参数时指定另一个]的可能重复(http://stackoverflow.com/questions/11455218/python-argparse-enable-input-parameter-when-another-one-已被指定) – mgilson 2012-08-01 13:46:50