0

I want to add some arguments based in other argument value. I mean, something like:

parser.add_argument("-e", "--example", type=str)

args = parser.parse_args()
if args.example = "example":
    parser.add_argument("-j", "--othervalue", type=str) # I know that it is failing.

Any idea?

Juan Garcia
  • 843
  • 2
  • 11
  • 34
  • You can't add arguments after parsing the command line, no. Add the `-j` option *at the start* and use `parser.error()` if it is used without `-e example`. – Martijn Pieters Dec 11 '17 at 16:27
  • You might get this to work with a `parse_known_args` to detect the `example`, and then a new `parse_args` after adding the `othervalue` Action. – hpaulj Dec 11 '17 at 17:56

0 Answers0