python get subparser name

Solutions on MaxInterview for python get subparser name by the best coders in the world

showing results for - "python get subparser name"
Daphné
17 Feb 2019
1import argparse
2
3parser = argparse.ArgumentParser()
4subparsers = parser.add_subparsers(dest='command')
5parser_python = subparsers.add_parser('python', help='some sub-command')
6# ...
7parser_java = subparsers.add_parser('java', help='some other sub-command')
8# ...
9args = parser.parse_args(command_line)
10
11if args.command == 'python':
12  # do something
13elif args.command == 'java':
14  # do something else