Python argparse conditional arguments

2019-08-01 09:01发布

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条回答
Deceive 欺骗
2楼-- · 2019-08-01 09:25

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')
查看更多
登录 后发表回答