我正在尝试在Argparse中设置以下条件:
- 如果
- StartDate
然后需要 - endDate
,
- 如果
- montry
然后需要 - 年
- 如果
- Week_num
然后需要 - 年
仅需要上述项目符号项目之一,即1或2或3如果指定了多个,则出错。因此,基本上用户可以指定开始日期和结束日期,或一个月和年度或每周和年。
例如:
$ myprog -startdate 01-01-2022 - enddate 01-07-2022
$ myprog- myprog- minth 1 - 年度2022
或
$ myprog - 周1年 - 2022年
如果用户这样做,则应该有一个错误:
$ myprog-周1- enddate 01-07-2022
我不确定如何使用ArgParse完成此操作。我研究了互斥的群体,但这似乎不允许配对。
I am trying to set the following conditions in argparse:
- If
--startdate
then require --enddate
,
- If
--month
then require --year
- If
--week_num
then require --year
Only require one of the above bullet items, i.e, either 1 or 2 or 3, and if more than one is specified then error out. So basically the user can specify the start and end date, or the month and year or the week and year.
For example:
$ myprog --startdate 01-01-2022 --enddate 01-07-2022
OR
$ myprog --month 1 --year 2022
OR
$ myprog --week 1 --year 2022
If a user does something like this, then there should be an error:
$ myprog --week 1 --enddate 01-07-2022
I am not sure how to accomplish this using argparse. I looked into mutually exclusive groups, but that seems to not allow for pair.
发布评论