strange __call__

Steven Bethard steven.bethard at gmail.com
Wed Jun 29 16:03:53 EDT 2005


Rahul wrote:
> def wrapper(obj):
>    g = obj.__call__
>    def f(*args,**kwargs):
>      for arg in args:print arg
>      return g(*args,**kwargs)
>    obj.__call__=f
> but it seems this will not work for functions :(

def wrap(obj):
     def f(*args, **kwargs):
         for arg in args:
             print arg
         return obj(*args, **kwargs)
     return f

@wrap
def func(a, b, c):
     ...

class C(object):
     ...
C = wrap(C)

STeVe



More information about the Python-list mailing list