Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple level arguments processing with `optparse`

Tags:

python

What I mean by multiple level arguments is something like svn help, after parsing the svn help part, the following word is considered argument to help the subcommand.

Is it possible to set this up with optparse?

like image 216
satoru Avatar asked Sep 15 '25 07:09

satoru


1 Answers

According to the python docs, optparse is now considered as deprecated, and won't be developed further; therefore i would strongly suggest you to use the module argparse, whith which you can create "multiple level" arguments.

import argparse
parser = argparse.ArgumentParser()

# Init sub-command
parser_init = subparsers.add_parser('init', help='initialize the things')
parser_init.add_argument(...)

# Help sub-command
parser_help = subparsers.add_parser('help', help='help me!')
parser_help.add_argument(...)
like image 52
mgalardini Avatar answered Sep 17 '25 22:09

mgalardini