print(hasattr(t.test_while1,'__func__')) #True
x = testCar.test_while1.__class__.__name__
print(x) #function
y =test_while1.__class__.__name__
print(y) #function
z =testCar.a.__class__.__name__
print(z) #int
#c =testCar().__class__.__name__
c =testCar.__name__ #<---正确 ()-->class转换掉了。
print(c) #testCar
c1=test_while1.__class__.__name__
print(c1) #function
c2 =testCar.a.__getattribute__
print(c2)
def checkClass():
print(f"反射当前类:{TestClass.__name__}")
def checkFunc():
print(f"反射当前函数:{TestClass.funcTest.__name__}")
class TestClass:
def funcTest(self):
checkClass()
checkFunc()
tc =TestClass()
tc.funcTest()
hasattr 还有几个以及一些魔法方法,看懂上面的,可以愉快的玩反射了。