1

I am creating a program that requires conditional arguments using argparse. I would like to generate new arguments in my code depending on if a previous argument has been entered or not. Here is a basic example of how I would like my code to look

import argparse
parser = argparse.ArgumentParser()

parser.add_argument("-bowtie",action = "store_true",help="use to run bowtie")
args = parser.parse_args()

if args.bowtie:
    parser.add_argument( add some new argument here )
    args = parser.parse_args()
1
  • Look at using a subparser to add arguments to a bowtie subcommand. Commented Feb 25, 2013 at 23:17

1 Answer 1

2

I've been doing a lot of stuff recently that's really similar to this. Look into subparsers:

parser = argparser.ArgumentParser
subparsers = parser.add_subparsers('-bowtie')
subparser = subparsers.add_parser()
subparser.add_argument('new argument')
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.