#!/usr/bin/env python
class parent:
def __init__(self):
self.name = 'parent'
def getName(self):
print(self.name)
class child:
def getName(self):
#如何访问到父类的name值
if __name__ == '__main__':
child = parent.child()
child.getName()
parent.name does not exist before parent is instantiated, so child cannot access parent.name
There are two methods
Or instantiate the parent first and then pass the parameters in