The differential in cmd and argparse is that cmd is a "line-oriented command interpreter" and argparse is a parser for sys.argv .
In your example, sys.argv analyzed, which you pass during the start of your program, and then, if it receives a value, you start the function and then exit.
argparse will only sys.argv during program startup.
You can add code for working with args , which you pass as a function or class, or make a program menu that you can use with raw_input . Example:
class Main(): def __init__(self, create=None, send=None): if create: self.create(create) elif send: self.send(send) option = raw_input('What do you want to do now?') print option def create(self, val): print val def send(self, val): print val if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('-c','--create' ,help='',action='store_true') parser.add_argument('-s','--send',help='',action='store_true') args = parser.parse_args() Main(args.create, args.send)
Other then python argparse and control / override of exit status code or python argparse - add action to subparse without arguments? can help.
The first shows how you can override quit, and the second shows you how to add subcommands or quitactions.
source share