Opster: Pythonic option parsing
blogg.ingspree.net
blogg.ingspree.net
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.
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-oreientedFor 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.
But, 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...
> but I realize that none of this will be fixed until > there’s a cultural shift in Python away from this > habit of Neglect.
Did that end up motivating any positive change?
http://bazaar.launchpad.net/%7Ezedshaw/lamson/development/an...
Choice example: command function (can’t invent better name, sorry) need to have preformatted name (like command_ping).
This is incorrect. From the documentation: Note that the _command suffix is optional and configurable, but it is there to disambiguate your commands so you can use Python reserved words and base types as your command names. Without it, you can do a list_command or a for_command. This is after line 10 of the Lamson argument source file. Couldn't read that far I guess.
I wont bother addressing his other points. Putting in effort to refute an argument put together with no effort is nothing something I enjoy doing.