Let's say I have a python test using argparse, with several arguments:
Sometimes, I'd like to change the default enabled_features, let's say to [A,B,C,D]:
So is there an attribute in the argparse classes to know, after:
opts = parser.parse_args()
...that an argument was actually specified by the user, i.e. that one has used something like:
$ python my_test.py --enabled_features A B C
and not:
$ python my_test.py
Thanks!
opts
contains all the information that argparse
can give you. So you have to either test for some default value (most commonly None
), or the absence of the attribute (if default=argparse.SUPPRESS
).
Another approach is to specify a reasonable default
, and not worry whether the user specified those, or other values, in the input. Which is more important, that the user specified the values, or the values themselves?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With