2

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')

1 Answer 1

3

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.