Reputation: 151
I want to use Python ArgParse to accept only certain inputs from the user.
So in below example let's say I want to accept 'type1/type2/type3' as argument only. Is that possible?
parser.add_argument('-t', '--type', type = str, help = 'type1/type2/type3')
Upvotes: 2
Views: 333
Reputation: 1121494
Use the choices
argument to limit the input to a limited set of choices:
parser.add_argument('-t', '--type', choices=('type1', 'type2', 'type3'),
help='type1/type2/type3')
Upvotes: 3