Paul Miller wrote:

While on the subject, is there an equivalent for "methodcaller"?

ie. if I want to bind a function which calls a specific method of an object with a specific parameter?


def funccaller(func, *args, **kwargs): def _return_func(): return func(*args, **kwargs) return _return_func

class Test1(object):
    def __init__(self, x):
        self.x = x
    def method(self, a, b, c):
        return self.x + a + b + c

t1 = Test1(42)

funccaller_result = funccaller(t1.method, 3, 4, c=5)
funccaller_result()

And this time I actually tested it, and it works! ;)
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to