strange __call__

Rahul codedivine at gmail.com
Wed Jun 29 16:23:12 EDT 2005


If you do C = wrap(C) C no longer remains a class..it becomes a
function.

Steven Bethard wrote:
> 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