-
getattr()函数:
这个函数可以直接读取一个未实例化的类中的内容:
①获取一个变量的值:class A(object): first = "this is first" print(getattr(A ,"first"))
结果会输出 this is first;
② 获取一个类:
class A(object):
class B(object):
second = "B"
def func():
print("this is B")
a = getattr(A,"B")
a.func()
结果会输出 this is B.