determining method type (instance, static, class)

Alexander Schmolck a.schmolck at gmx.net
Tue Jan 28 12:30:10 EST 2003


Michael Hudson <mwh at python.net> writes:

> Alexander Schmolck <a.schmolck at gmx.net> writes:
> 
> > How can one determine whether a method .foo is a normal instance
> > method or a classmethod or a staticmethod?
> 
> Using isinstance.  

Hmm, yes, but not in the straightforward way:

  >>> isinstance(bar.foo, classmethod)
  0

Jp Calderone helpfully suggested:

  >>> isinstance(bar.__dict__.['foo'], classmethod)
  1

I must say this behavior seems unintuitive and ugly to me and Jp's solution
also won't work if I have *just* the method. What's the reason for it?

> Why do you want to know?

To automatically generate function equivalents of methods.


alex




More information about the Python-list mailing list