Skip to content

Tag: argparse

Disable/Remove argument in argparse

Is it possible to remove or disable an argument in argparse, such that it does not show in the help? How? It is easy to add new arguments: And I know you can override arguments with a new definition by specifying the “resolve” conflict handler: But this still includes arg1 in the help message and …

Argparse: Required argument ‘y’ if ‘x’ is present

I have a requirement as follows: for the argument prox , I use action=’store_true’ to check if it is present or not. I do not require any of the arguments. But, if –prox is set I require rport and lport as well. Is there an easy way of doing this with argparse without writing custom conditio…

Python argparse conditional requirements

How do I set up argparse as follows: For example, There are a number of similar questions here, but either they don’t address this situation or I don’t understand. Python 2.7 if that matters. Answer A subparser (as suggested in comments) might work. Another alternative (since mutually_exclusive_gr…

How can I pass a list as a command-line argument with argparse?

I am trying to pass a list as an argument to a command line program. Is there an argparse option to pass a list as option? Script is called like below Answer SHORT ANSWER Use the nargs option or the ‘append’ setting of the action option (depending on how you want the user interface to behave). nar…