Answers for "python get subparser name"

0

python get subparser name

import argparse

parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='command')
parser_python = subparsers.add_parser('python', help='some sub-command')
# ...
parser_java = subparsers.add_parser('java', help='some other sub-command')
# ...
args = parser.parse_args(command_line)

if args.command == 'python':
  # do something
elif args.command == 'java':
  # do something else
Posted by: Guest on June-17-2020

Python Answers by Framework

Browse Popular Code Answers by Language