Dynamically creating page definitions in Cherrypy
- by Hugh
Hi,
I've been looking around the CherryPy documentation, but can't quite get my head around what I want to do. I suspect it might be more of a Python thing than a CherryPy thing...
My current class looks something like this:
import managerUtils
class WebManager:
def A(self, **kwds):
return managerUtils.runAction("A", kwds)
A.enabled = True
def B(self, **kwds):
return managerUtils.runAction("B", kwds)
B.enabled = True
def C(self, **kwds):
return managerUtils.runAction("C", kwds)
C.enabled = True
Obviously there's a lot of repetition in here.
in managerUtils.py, I have a dict that's something like:
actions = {'A': functionToRunForA,
'B': functionToRunForB,
'C': functionToRunForC}
Okay, so that's a slightly simplistic view of it, but I'm sure you get the idea.
I want to be able to do something like:
import managerUtils
class WebManager:
def __init__(self):
for action in managerUtils.actions:
f = registerFunction(action)
f.enabled = True
Any ideas of how to do this?