from optparse import OptionParser
parser = OptionParser() # initialise parser
parser.add_option(...) # add option 1
parser.add_option(...) # add option 2
(options, args) = parser.parse_args() # run parser, get values
..and the sample add_option call: parser.add_option(
"-q",
"--quiet",
action="store_false",
dest="verbose",
default=True,
help="don't print status messages to stdout")
I don't see anything repetitive, nor unnecessarily object-oreientedBut, at first glance, this new 'opster' doesn't try to address that.
defaults = load_stored_config_to_dict('example.conf')
parser.add_option(
"-q",
"--quiet",
action="store_false",
dest="verbose",
default=defaults['quiet'],
help="don't print status messages to stdout")More discussion of this problem: http://deadbraincells.org/configopt/docs/configopt.html http://wiki.python.org/moin/ConfigParserShootout#ConfigParse...
For my current project at work, we're using optparse along with the configparse extension to read config files, and a bunch of monkey-patching to make it all work well together. Further development in the realm of runtime configuration is welcome, if frustratingly diverse at times.
I only have experience with the default "optparse", and not "argparse" or any others. While optparse seems like more than enough for what I use, I know of exotic command line bastardizations that optparse would never be able to handle without some tweaks.
(I fully expect someone to now come and tell me how to get it to handle positional arguments easily)
# Check which arguments are available
# Cast them
# Provide utilization information for the arguments
# Provide defaults
# Do all the other stuff that optparse does for options
Hmm... I guess Google's argparse really is the future.