0

I was wondering how coul i execute a function in python with just a call of an argument when running that command, for example,

parser = argparse.ArgumentParser(description="Database accounts manager")
parser.add_argument("-s", "--show", help="Shows all database rows and columns", dest="show",required=False)

args = parser.parse_args()

if args.show:
     print("i am beautiful")

what i would like is to when i call this file : python file.py -s or python file.py --show, i would like it to execute a function like i wrote for an example : "print("i am beautiful")

because when i do that i need to give an argument so it executes the function: "print(...)"

1 Answer 1

1

Add action to the parameters:

parser.add_argument("-s", "--show", help="Shows all database rows and columns", dest="show",required=False, action="store_true")
Sign up to request clarification or add additional context in comments.

3 Comments

i was thinking and i'm going to try to do "nargs=0" let's see but what is that action parameter for?, because i dont want to store any value since im not gonna give any value u understand?, could i use action to execute a function? insteaed of "store_true" can i pass like "funcshow" =??
oh ok. so i tried nargs=0 and it says i should use actions but since i don't want to store any value what should i use then=?
i used what u wrote up there and it works now so thanks a lot bro :D im dumb as hell ahhahah

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.