python - How do I check for a particular subparser? -


how check particular subparser?

import argparse if __name__ == "__main__":     mainparser = argparse.argumentparser()     submainadder = mainparser.add_subparsers(title='subcommands')     parser_ut = submainadder.add_parser('unittest')     stuff = mainparser.parse_args()     # if 'unittest' selected:     #     do_things() 

maybe ?

import argparse  def do_things(args):     print args     # stuff  mainparser = argparse.argumentparser() submainadder = mainparser.add_subparsers(title='subcommands') parser_ut = submainadder.add_parser('unittest') parser_ut.set_defaults(func=do_things)  if __name__ == "__main__":     stuff = mainparser.parse_args()     stuff.func(stuff) 

more explanations can found here:

python argparse - add action subparser no arguments?


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -