I'm using argparse to use user arguments to run functions in my program which is running just fine. But I'm unable to run other generic functions which I'm calling in main(). It just skips those functions without running and showing output. How do I do it or where am I doing wrong ?
Let's say in below program I want functions mytop20 and listapps to be run using user arguments which runs fine if I remove the boilerplate main() function but my objective is run_in_main() function should run in main()
import argparse
def my_top20_func():
print "Called my_top20_func"
def my_listapps_func():
print "Called my_listapps_func"
def run_in_main():
print "Called from main"
parser = argparse.ArgumentParser()
FUNCTION_MAP = {'top20' : my_top20_func,
'listapps' : my_listapps_func }
parser.add_argument('command', choices=FUNCTION_MAP.keys())
args = parser.parse_args()
func = FUNCTION_MAP[args.command]
func()
if __name__ == "__main__":
run_in_main()
As my use case is quite similar I have taken above code from here.