[Tutor] Intercepting methods calls

Andreas Kostyrka andreas at kostyrka.org
Thu Jun 5 12:52:55 CEST 2008


On Thursday 05 June 2008 12:31:56 you wrote:
> On Jun 5, 2008, at 6:06 PM, Andreas Kostyrka wrote:
> > well, don't return a string :-P
> >
> > class CallableString(str):
> >   def __call__(self, *args, **kw):
> >      return self
> >
> > And now instead of return '', write return CallableString('')
>
> Whoa, trippy.
>
> That certainly works, but it's a workaround to the original question –
> is there actually any way to 'detect' an attribute/method call?

No, because there are no "method calls" in Python.

obj.method() 

  means:

  locate obj in locals/globals.

  locate method on obj

  call the found thing.

obj => obj.method => obj.method()

Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/tutor/attachments/20080605/519df774/attachment.pgp>


More information about the Tutor mailing list