python argparse integer condition (>=12)
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 thers's a way to obtain this result directly with some
argparse option.
No comments:
Post a Comment