[stdlib-sig] Pyopt - command-line options that are alot easier than optparse
Michael Foord
michael at voidspace.org.uk
Thu Sep 10 11:21:33 CEST 2009
Yuvgoog Greenle wrote:
> Hi stdlib-sig,
>
> I wanted to ease exposing functions to the command-line using python 3
> features and the result is http://code.google.com/p/pyopt/
>
> I think this could be good stuff for the standard library and I'm not
> sure how to go about it, should I work on integrating with
> optparse/optik (is that project still active?) or should this be a
> separate module?
For a module to be accepted into the standard library it typically
already needs to be in use by the Python community and recognised as
'best-of-breed'.
*Personally* I would like to see argparse in the standard library as I
think it is currently the best Python argument parsing library, but that
is just my opinion. As we already have two argument parsing libraries in
the standard library (getopt and optparse) the addition of a third for
the *same* task is highly unlikely.
On the other hand, if you can provide your functionality as an addon-for
optparse - retaining full backwards compatibility - then it may be
accepted as an extension of the existing module rather than as a new one
(a much lower bar).
All the best,
Michael Foord
>
> This is an example usage of pyopt.0.71:
> ---
> import pyopt
> expose = pyopt.Exposer()
>
> @expose.args
> def possy(archer:str, boulder:float, magic:int=42):
> """Shows an example positional command-line function.
> archer - is a str
> boulder - should be a float
> magic - a number that is magical"""
> print(repr(archer), repr(boulder), repr(magic))
>
> if __name__ == "__main__":
> expose.run()
>
> ---
> And this is what you get:
>
> C:\>example.py -h
> Usage: example.py archer boulder [magic]
> Shows an example positional command-line function.
> archer - is a str
> boulder - should be a float
> magic - a number that is magical
>
> C:\>example.py 1 2 3
> '1' 2.0 3
>
> C:\>example.py 1 2
> '1' 2.0 42
>
> C:\>example.py 5
> 2 arguments required, got only 1. Run with ? or -h for more help.
> ---
>
> For more examples and functionality (like multiple functions) look at:
> http://code.google.com/p/pyopt/wiki/Examples
>
> Notes:
> 1. I know the names aren't perfect (module pyopt, class Exposer and
> the decorator methods args/kwargs/mixed). Please reply if you have
> better names in mind.
> 2. I realize this isn't as flexible as optparse and passing options
> around multiple different sub-functions is harder. This module is
> strictly a quick and clean solution to a very day-to-day use case:
> bridging python functions to command-line.
> 3. Feedback would be greatly appreciated. I would like to know if I'm
> the only one who's tired of sys.argv/optparse boilerplate.
>
> --
> Yuv
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> stdlib-sig mailing list
> stdlib-sig at python.org
> http://mail.python.org/mailman/listinfo/stdlib-sig
>
--
http://www.ironpythoninaction.com/
More information about the stdlib-sig
mailing list