![](/img/trans.png)
[英]How to set and get a parent class attribute from an inherited class in Python?
[英]How to get only the function names in an inherited class in python
如何在python中仅获取继承类中的函数名称
class A(object):
def Afunc1(self):
pass
def Afunc2(self):
pass
class B(A):
def Bfunc1(self):
pass
def Bfunc2(self):
pass
有没有办法只获取 B 类中的函数名而不是 A 类中的函数名
这应该有效:
from types import FunctionType
functypes = (FunctionType, classmethod, staticmethod)
[name for name, value in B.__dict__.items() if isinstance(value, functypes)]
可以使用vars
函数获取类B
本身的属性 dict 并过滤掉不可调用的类和类:
[k for k, v in vars(B).items() if callable(v) and not isinstance(v, type)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.