您当前的位置: 首页 >  Python

彭世瑜

暂无认证

  • 0浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Python:获取类中除内置方法外的所有方法名

彭世瑜 发布时间:2020-10-30 17:58:13 ,浏览量:0

# -*- coding:utf-8 -*-


class Clazz:
    name = ""

    def getName(self):
        pass

    def getAge(self):
        pass


def get_methods(self):
    return (list(filter(lambda m: not m.startswith("_") and callable(getattr(self, m)),
                        dir(self))))


if __name__ == '__main__':
    print(dir(Clazz))
    """
    ['__class__', '__delattr__', '__dict__', 
    '__dir__', '__doc__', '__eq__', '__format__', 
    '__ge__', '__getattribute__', '__gt__', '__hash__', 
    '__init__', '__init_subclass__', '__le__', '__lt__', 
    '__module__', '__ne__', '__new__', '__reduce__', 
    '__reduce_ex__', '__repr__', '__setattr__', 
    '__sizeof__', '__str__', '__subclasshook__', 
    '__weakref__', 'getAge', 'getName', 'name']
	"""
    print(get_methods(Clazz))
    # ['getAge', 'getName']

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.1952s