开发者

How can I tell if a given method is a classmethod or instancemethod in Python?

Checking to see if m.im_self is the class works some of the time but doesn't seem开发者_Go百科 to be 100% reliable (ex. if you use multiple decorators on a method.)


If it's a bound method on the class then it's a classmethod.

from inspect import ismethod, isclass
def isclassmethod( m ):
 return ismethod(m) and isclass(m.__self__)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜