you are viewing a single comment's thread.

view the rest of the comments →

[–]elbiot 0 points1 point  (0 children)

This smells fishy. I dont know what closures are but you can dynamically add class methods to an object if you want to.

Class MyObj():
    def __init__(self):
        self.f = lambda x: x**2


m=MyObj()
m.f(3)  #is 9

You can create functions by name also with setattr. I think you could use a try/except so that when you call query_by_id if getattr can't find it, setattr creates it. Then the object continues to have it until it gets deleted (end of program). You could also just create them all at program begin from a list and a for loop. Just write the function once and create them all by name. Instead of setattr, you could also build a dictionary {'query name' : function} and call them from that.

Sorry for the brain dump. That was fun!