Python OOP

获取类的属性、方法、函数等

inspect

1
2
3
4
# get the attributes which are not class method
attrs = inspect.getmembers(self, lambda x: not inspect.ismethod(x))
# filter the private attributes
attrs = [x[0] for x in filter(lambda x: not x[0].startswith('__'), attrs)]