pyopt

Exposing Python functions to the command-line
Download

pyopt Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • ubershmekel
  • Publisher web site:
  • http://code.google.com/u/ubershmekel/

pyopt Tags


pyopt Description

Exposing Python functions to the command-line pyopt is a Python 3 module for command-line options with a pythonic, decorator-centric syntax.The following example auto-generates help with docstrings, type casting for arguments and enforcing argument count: import pyopt import random expose = pyopt.Exposer() @expose.args def roll_dice(number_of_faces:int, repetitions:int): ''' Roll the dice to see if you are lucky or for general D&D pleasure. number_of_faces - the max value of the die. repititions - the amount of times to throw the dice. ''' for i in range(repetitions): print(random.randint(1, number_of_faces)) expose.run()There are 3 modes of operation:1. expose.args - A decorator for positional arguments.2. expose.kwargs - A decorator for keyword arguments.3. expose.mixed - A decorator for keyword and positional arguments.Currently known compromises that are open to discussion, e-mail me:1. This module was specifically designed with python 3 in mind, certain features can be converted to python 2.x, but the awesome ones can't.2. Keyword command-line functions require every argument to start with a different letter to avoid collisions.3. Annotations aren't mandatory, I don't know if this is the right way to go, it's an explicity vs convenience issue.4. Booleans can't default to false. I couldn't think of a use case for this so tell me if you did. Requirements: · Python


pyopt Related Software