0
我的程序有两个功能。一个没有任何参数运行,另一个可以有可选的参数。这些群体不能相互干扰。如何拥有两个独立的组
import argparse
parser = argparse.ArgumentParser()
root_group = parser.add_mutually_exclusive_group()
group_export = root_group.add_argument_group()
group_export.add_argument('--export', action='store_true', help='Exports data from database')
group_export.add_argument('-l', action='append', help='Reduce output with league name')
group_export.add_argument('-d', action='append', help='Reduce output with date range')
group_run = root_group.add_argument_group()
group_run.add_argument('--run', action='store_true', help='Start gathering of data')
我想这是允许的:
python file.py --export -l name1 -l name2 -d 1/1/2015
python file.py --export
python file.py --run
而这是不允许的:
python file.py --run --export # Namespace(d=None, export=True, l=None, run=True)
python file.py --run -l name1 # Namespace(d=None, export=False, l=['name1'], run=True)
然而,作为现在无论是不允许操作的上升一个错误,因为由评论表示。