- 论坛徽章:
- 0
|
本帖最后由 千年沉寂 于 2010-04-21 09:31 编辑
如题,即A继承B,B继承A
code 1:- class Mama(object):
- def says(self):
- print 'Do your homework'
- class Sister(Mama):
- def method(self):
- print 'Mama said'
- def says(self):
- super(Sister,self).says()
- print 'and clean your bedroom'
- anita = Sister()
- anita.says()
复制代码 output 1:
Do your homework
and clean your bedroom
code 2:- class Mama(Sister):
- def says(self):
- super(Mama,self).method()
- print 'Do your homework'
- class Sister(Mama):
- def method(self):
- print 'Mama said'
- def says(self):
- super(Sister,self).says()
- print 'and clean your bedroom'
- anita = Sister()
- anita.says()
复制代码 output 2:
Mama said
Do your homework
and clean your bedroom
直接运行第二段代码会出错,刚注意到。我用的是pyscripter做编辑器,python引擎是通过Rpyc调用解释解释执行。
刚开始是运行“code 1”得到“output 1”,把“code 1” 改成“code 2”,再运行,则正常,结果为“output 2”,即“code 3”可以直接运行,得到“output 2”
code 3- class Mama(object):
- def says(self):
- print 'Do your homework'
- class Sister(Mama):
- def method(self):
- print 'Mama said'
- def says(self):
- super(Sister,self).says()
- print 'and clean your bedroom'
- class Mama(Sister):
- def says(self):
- super(Mama,self).method()
- print 'Do your homework'
- class Sister(Mama):
- def method(self):
- print 'Mama said'
- def says(self):
- super(Sister,self).says()
- print 'and clean your bedroom'
- anita = Sister()
- anita.says()
复制代码 |
|