5

I have the following scenario for command line argument. If there is a particular option then there should be some other required options. For example if there is -- create then there should be --name. Also if there is --remove then there should be --id. Is it possible to implement this scenario with argparse? or someother thing?

2 Answers 2

8

This can be done with subcommands as long as you don't mind create and remove not being preceded with hyphens. This may make sense anyway, since those verbs are often used as actions rather than options.

Sign up to request clarification or add additional context in comments.

1 Comment

@bonzi: Cheers. Don't forget to accept the answer if it does end up being the solution to your problem.
1

Optional is implicit, required must be specified:

http://docs.python.org/library/argparse.html#required

That said, there doesn't appear to be a built-in mechanism for argument "dependencies", as I think you would like to implement. This would be a requirement for your application.

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.