class Person: def __init__(self): self.name = "zjgtan" def getName(self): return self.name反射的簡單含義:
通過類名獲得類的實例對象
通過方法名得到方法,實現(xiàn)調(diào)用
反射方法一:
from person import PersontheObj = globals()["Person"]()PRint theObj.getName()反射方法二:
module = __import__("person")theObj = getattr(module, "Person")()print theObj.getName()
|
新聞熱點
疑難解答