problem with closure arguments and *args in mock object

John J. Lee jjl at pobox.com
Fri Nov 7 16:28:12 EST 2003


Peter Otten <__peter__ at web.de> writes:
[...]
> Not very elegant, but might still serve the purpose:
> 
> class Test(object):
>     def __init__(self):
>         self.log = []
>     def handle(self, args):
>         self.log.append(args)
>     def define(self, methods):
>         def makeMethod(name):
>             def method(self, *args):
>                 self.handle((name,) + args)
>             return method
>         for name in methods:
>             setattr(self.__class__, name, makeMethod(name))
[...]

I forgot to say, I'm trying to do this with 1.5.2.  Is this possible?
Any ideas for best alternative if not?


John




More information about the Python-list mailing list