determining method type (instance, static, class)

Jp Calderone exarkun at
Mon Jan 27 00:25:43 CET 2003

On Sun, Jan 26, 2003 at 10:30:06PM +0000, Alexander Schmolck wrote:
> How can one determine whether a method .foo is a normal instance method or a
> classmethod or a staticmethod?

With type() and the class's __dict__ attribute:

def bar(): pass

class Foo:
    def bar(): pass
    s_bar = staticmethod(bar)
    c_bar = classmethod(bar)

Foo.f_bar = bar

print map(type, 
    map(Foo.__dict__.__getitem__, ('bar', 's_bar', 'c_bar', 'f_bar'))

  You probably shouldn't want this information except in special cases where
your purpose is explicitly introspection, for debugging or a class browser
or something similar.


 up 42 days, 3:49, 8 users, load average: 0.11, 0.21, 0.18
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list