0

I am taking the user input in such a way

parser.add_argument("ratio", metavar="fakeratio", type=check_ratio, help="Some fake ratio")

here check_ratio is method checking if the value is positive and returns float.

My Question: I want to add another argument parser asking user to use --f option if the ratio > 1. I understand that parser will parse all the arguments in one go. It doesnt have yield (as per my best knowledge). So how can I use --f option if the user has given ratio >1. This --f option will not do anything as such. It will just enforce user to use --f if they give value ratio>1.

JustCurious
  • 111
  • 3
  • 14
  • Would be easier to split out your application logic out of argparser - use the argparser only for raw input arguments and then initialize your application with those values inside code blocks you have full control. – metatoaster Sep 02 '20 at 05:40
  • I realized so. I understood that the argeparse's main job is to take the arguments and any further checks should be at user's discretion. But just for my knowledge, I want to know if there is a way. – JustCurious Sep 02 '20 at 05:58
  • 1
    No, there is no way to do [mutually inclusive option](https://stackoverflow.com/questions/19414060/argparse-required-argument-y-if-x-is-present), let alone one with specific conditions. [This answer](https://stackoverflow.com/a/25626676) may point towards something you can attempt to implement. – metatoaster Sep 02 '20 at 06:10

0 Answers0