the annoying, verbose self
steven at REMOVE.THIS.cybersource.com.au
Wed Nov 28 02:30:31 CET 2007
On Tue, 27 Nov 2007 10:11:48 +0100, Bruno Desthuilliers wrote:
> Fine. Now since Python let you define your own callable types and your
> own descriptors, you can as well have an attribute that behave just like
> a method without being an instance of any of the method types - so the
> above test defeats duck typing. And since you can have callable
> attributes that are definitively not methods, you can't rely on the fact
> that an attribute is callable neither.
I did say the usual way was to call it and see what happens :)
(In Python3, I understand that is what callable() will do. Let's hope
that the function called has no side-effects.)
I also didn't mention classmethods, staticmethods or functions assigned
to attributes. As Ton van Vliet is a beginner, I didn't think he needed
to be flooded with too many complications all at once. It's quite
possible to program in Python for years and never come across a callable
attribute that isn't an ordinary method.
Also, I wasn't actually thinking about testing for methods before calling
them. Given the context, I was thinking more about manual experimentation
at the interpreter. Perhaps I should have said.
More information about the Python-list