python 3 argparse call a function
问题 I wanted to create a commandline-like / shell-like interface in python3. Argparse seems to do the job of parsing and displaying the help/error messages. According to the python3 documentation of argparse, there is a func= argument that can be used to get your function called by argparse . # sub-command functions def foo(args): print(args.x * args.y) def bar(args): print('((%s))' % args.z) # create the top-level parser parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() #