the annoying, verbose self

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Tue Nov 27 03:17:22 EST 2007


On Mon, 26 Nov 2007 21:48:36 +0100, Ton van Vliet wrote:

> On Mon, 26 Nov 2007 20:14:50 +0100, Bruno Desthuilliers
> <bdesth.quelquechose at free.quelquepart.fr> wrote:
> 
>>> However, I was more thinking in terms of attributes only
>>
>>Too bad : in Python, everything's an object, so 'methods' are attributes
>>too.
> 
> Right, but I'm sure *you* know a way to distinguish between them (I'm
> just a beginner ;-)

All methods are attributes. Not all attributes are methods. The usual way 
to see if something is a method is to try calling it and see what 
happens, but if you want a less informal test, try type():


>>> type(''.join)
<type 'builtin_function_or_method'>
>>> type(Foo().foo)  # with the obvious definition of Foo
<type 'instancemethod'>




-- 
Steven



More information about the Python-list mailing list