I am writing the script where I pass values with CLI through argparse
module. I am wondering if this is possible to restrict variable to hold pre-defined values, to avoid user mistake. It is not the type restriction, values are consists of letters as well as digits, surely I can write an if
block, but I have about 30 pre-defined values, so writing something like
if var is value1 or var is value2 ... or var is value30:
pass
else:
print("oops, your value does not fit")
would be painful. What is the proper way of doing this?
With
choices
:Accepted:
rejected:
help:
If I'd defined a
metavar
, the help will beOr if the choices is too long, define a
type
function: