k3xji wrote:

> Hi,
> 
> Is there a way to hook a function call in python? I know __getattr__
> is doing for variables, it is giving us a chance before a field is
> initialized. Do we have same functionality for methods?
> 
> Example:
> 
> class Foo(object):
>     def __call_method__(self, ...) # just pseudo
>         print 'A method is called in object...'
> 
> f = Foo()
> f.test_method()
> 
> I think you understand my point.

The special method __call__ is your friend.


class SomethingCallable(object):

   def __call__(self):
      print "I'm called, and you not!"

SomethingCallable()()

Diez
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to