class father():
def __init__(self):
self._name = "aaa"
def fun1(self):
method = eval('self.' + 'ss' + '_db')
print(method)
def fun2(self):
tt = self.ss_db
print(tt)
class son(father):
def __init__(self):
father.__init__(self)
self.ss_db = "daas"
def getname(self):
print(self._name)
return self._name
if __name__ == "__main__":
son = son()
son.fun1()
son.fun2()
son.getname()
输出:
daas
daas
aaa