[stdlib-sig] Pyopt - command-line options that are alot easier than optparse

Brett Cannon brett at python.org
Thu Sep 10 03:27:51 CEST 2009


On Wed, Sep 9, 2009 at 17:38, Yuvgoog Greenle <ubershmekel at gmail.com> 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?)

No, Optik simply became optparse.

> or should this be a separate module?

If you are simply asking for design advice, this is not the proper
place to ask. If you are wanting to get this module accepted into the
standard library it needs to have existed for some time and become
accepted by the Python community as the best solution for command-line
argument parsing.

-Brett

> 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
>
>


More information about the stdlib-sig mailing list