I need to request that an argument is >= 12 using argparse
.
I cannot find a way to obtain this result using argparse
, it seems there's no way to set rules to a given value but only full sets of accepted values like choices=['rock', 'paper', 'scissors'].
My code is:
import sys, argparse
parser = argparse.ArgumentParser()
parser.add_argument("-b", "--bandwidth", type=int, help="target bandwidth >=12")
args = parser.parse_args()
if args.bandwidth and args.bandwidth < 12:
print "ERROR: minimum bandwidth is 12"
sys.exit(1)
I wonder if there is a way to obtain this result directly with some argparse
option.
argparse.Action
, and override__call__
to create>=12
rule?type
, and points out that it is an adaptation of the documentation example, the one titledperfect_square
.