0

I have the following

p = ThrowingArgumentParser()
p.add_argument('action', type=str, choices=actions)
p.add_argument('args', nargs='*')

This is part of a multi level application. In level one, the command I care about is of the format command other-things-that-will-be-parsed-by-the-sub-module (for example get user john). So I'd except to get action = "get" and args = ["user", "john"].

So far so good. However, if I include a flag, all hell breaks loose (get user john --detailed). This will return a None. But I want to get the same as before: action = "get" and args = ["user", "john", "--detailed"].

Why is this failing?

1 Answer 1

1

I think you can use nargs=argparse.REMAINDER. Please see https://docs.python.org/3/library/argparse.html#nargs.

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.