0

This is the code so far:

parser = argparse.ArgumentParser()
args = parser.parse_args()
if args == 'a':
    _funct1()
elif args == 'b':
    _funct2()

I want the user to be able to call this script in such a way that

#python script_name -a

executes function 1

#python script_name -b

executes function 2

2
  • is it simply that you are missing import argparse Commented Jan 22, 2015 at 20:49
  • No, I have imported it. The error is: Unrecognized argument -a Commented Jan 22, 2015 at 20:51

1 Answer 1

1

Solved it, the correct code is:

parser = argparse.ArgumentParser()
parser.add_argument('-a', '--all', help='blah a', action='store_true')
parser.add_argument('-b', '--ball', help='blah b', action='store_true')
args = parser.parse_args()
if args.all:
    _all()
elif args.ball:
    _ball()
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.