Re: strange __call__

2005-06-29 Thread Rahul
Hi. I understood your point. thanks... rahul Steven Bethard wrote: > Steven Bethard wrote: > > > > 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):

Re: strange __call__

2005-06-29 Thread Steven Bethard
Steven Bethard wrote: > > 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) Rahul top-posted: > If you

Re: strange __call__

2005-06-29 Thread Reinhold Birkenfeld
Rahul wrote: > If you do C = wrap(C) C no longer remains a class..it becomes a > function. Does that matter? Reinhold -- http://mail.python.org/mailman/listinfo/python-list

Re: strange __call__

2005-06-29 Thread Rahul
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 thi

Re: strange __call__

2005-06-29 Thread Steven Bethard
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:

Re: strange __call__

2005-06-29 Thread Rahul
Hi. well if you do dir(a) just after defining 'a' then it does show '__call__'. the reason i wanted to do it is that i wanted to see if theres a uniform way to wrap a function and callable objects so that for example i can get some message printed whenever a function or a function-like-object is c

Re: strange __call__

2005-06-29 Thread Andreas Kostyrka
Just a guess, but setting "__X__" special methods won't work in most cases because these are usually optimized when the class is created. It might work if a.__call__ did exist before (because class a: contained a __call__ definition). Andreas On Wed, Jun 29, 2005 at 09:15:45AM +0100, Michael Hof

Re: strange __call__

2005-06-29 Thread Michael Hoffman
Rahul wrote: > Consider the following: > def a(x): > return x+1 > > def b(f): > def g(*args,**kwargs): > for arg in args: > print arg > return f(*args,**kwargs) > return g > > a.__call__ = b(a.__call__) > > now calling a(1) and a.__call__(1) yield 2 different results!! > i.e

strange __call__

2005-06-28 Thread Rahul
Consider the following: def a(x): return x+1 def b(f): def g(*args,**kwargs): for arg in args: print arg return f(*args,**kwargs) return g a.__call__ = b(a.__call__) now calling a(1) and a.__call__(1) yield 2 different results!! i.e. for functions a(1) doesnt seem to be tran