编程语言
首页 > 编程语言> > python 获取当前类中非私有方法

python 获取当前类中非私有方法

作者:互联网

参考:

(124条消息) Python:获取类中除内置方法外的所有方法名_彭世瑜的博客-CSDN博客_python 获取所有方法名

 

在类中加入如下函数,即可得到!



@classmethod
def get_methods(cls):
  return list(filter(lambda m: not m.startswith("_") and (m != "get_methods"), dir(cls)))

 

 

标签:methods,get,python,获取,私有,中非,方法,cls
来源: https://www.cnblogs.com/chenxiaolinembed/p/15684932.html