A simple templating system for Python class files.
Find this tool on PyPI
: pip install springform
Note: The following applies to the version currently on
PyPI
. Code in themain
branch now takes a different approach. Documentation to follow.
Given the following template file (let's call it Item.py
):
import time
from time import sleep
class Item:
copy = False
def __init__(self):
pass
def __str__(self):
return f"Copy status: {self.copy}"
and a reasonable driver (aw heck, let's call it main.py
):
from springform import Form
def __dumb(self):
print("It really is.")
def main():
template = Form(mod = "Item", cls = "Item")
template.remove("time")
template.add_base(object)
template.make("ItemCopy", copy = True, __dumb = __dumb)
if __name__ == "__main__":
main()
The module should make a new file in the current working directory: ItemCopy.py
whose __str__
magic will report to you that it's a copy (the above example changes
the value of the copy
instance variable).
As of a couple of minor versions ago (of course I forget which), you may not remove
things from the template by name and add inhertiances (well, as of 0.6.0
at least).
The module can handle single or multiple inheritance as of 0.2.0
-- find it everywhere
reputable Python modules are listed (i.e. only PyPI
, rly).
Obligatory "it's under construction" statement.