Skip to content

Commit 98aedaa

Browse files
committed
断点测试继承
1 parent c519211 commit 98aedaa

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/test_breakpoint.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python
2+
# encoding: utf-8
3+
4+
"""
5+
@author: zhanghe
6+
@software: PyCharm
7+
@file: test_breakpoint.py
8+
@time: 2017/10/22 下午11:02
9+
"""
10+
11+
12+
class Base(object):
13+
def __init__(self):
14+
self.info = 'Base class'
15+
print '%s init from Base' % self.info
16+
17+
def show(self):
18+
print '%s show from Base' % self.info
19+
20+
21+
class Child(Base):
22+
def __init__(self):
23+
self.info = 'Child class 01' # 子类先赋值再初始化父类, 子类其它方法里使用的这个同名变量是父类中赋的值(非期望,未覆盖)
24+
print '%s init from Child' % self.info
25+
# Base.__init__(self) # 普通继承
26+
super(Child, self).__init__() # super 继承
27+
self.info = 'Child class 02' # 先初始化父类子类再赋值, 子类其它方法里使用的这个同名变量是子类中赋的值
28+
29+
def show(self):
30+
print '%s show 01 from Child' % self.info
31+
super(Child, self).show()
32+
print '%s show 02 from Child' % self.info
33+
34+
35+
if __name__ == '__main__':
36+
child = Child()
37+
child.show()
38+
39+
40+
"""
41+
Child class 01 init from Child
42+
Base class init from Base
43+
Child class 02 show 01 from Child
44+
Child class 02 show from Base
45+
Child class 02 show 02 from Child
46+
"""

0 commit comments

Comments
 (0)