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

参考:

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

 

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


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

 

posted @ 2021-12-13 19:50  小小林林  阅读(83)  评论(0)    收藏  举报