Ideas for a module to process command line arguments

Alice Bevan–McGregor alice at gothcandy.com
Tue Jan 11 10:06:20 EST 2011


On 2011-01-11 00:32:32 -0800, Michele Simionato said:
> It's a pity that the argument parsing modules in the standard library 
> are so verbose that everybody is reinventing the same thing :-( It 
> looks like you have reinvented plac: http://pypi.python.org/pypi/plac

After looking into it, Plac's default help display isn't very helpful; 
you need to massage your application a fair amount before generating 
nice, complete-looking argument lists and such.  For example:

	def main(verbose: ('prints more info', 'flag', 'v'), dsn: 'connection 
string'):

	@annotate(dsn="connection string", verbose="prints more info")
	def main(dsn, verbose=False):

The latter is marrow.script, and even without the annotation a more 
complete help text is generated.  The -v and flag nature are assumed 
from the first unique character and default value.  (Flags, when 
present on the command line, invert the default value.)  Py3k 
annotations haven't been implemented yet, though.

Also included is an easy way to simulte command-line execution (i.e. by 
reading arguments passed by hand and by returning the exit code, vs. 
reading sys.argv and calling sys.exit()) for unit testing purposes.  
Plac appears (from the documentation) to be written on top of argparse. 
 :(

	- Alice.





More information about the Python-list mailing list