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')
asked Jul 4, 2015 at 10:55
user4723845
1612 gold badges3 silver badges9 bronze badges
1 Answer 1
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')
answered Jul 4, 2015 at 11:05
Martijn Pieters
1.1m326 gold badges4.2k silver badges3.5k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py