Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

The documentation for the argparse python module, while excellent I'm sure, is too much for my tiny beginner brain to grasp right now. I don't need to do the math on the command line or meddle with formatting lines on the screen or change option characters. All I want to do is "If arg is A, do this if B do that if none of the above show help and quit".

1 Answer

0 votes
by (106k points)

You can work with argparse (with multiple args) by using the following piece of code:-

parser = argparse.ArgumentParser(description='Description of your program')

parser.add_argument('-f','--foo', help='Description for foo argument', required=True)

parser.add_argument('-b','--bar', help='Description for bar argument', required=True)

args = vars(parser.parse_args())

The variable args will be a dictionary containing the arguments:

if args['foo'] == 'Hello':


if args['bar'] == 'World':


In your case, you should simply add only one argument.


Browse Categories