forked from progrmoiz/python-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasstree.py
More file actions
45 lines (30 loc) · 692 Bytes
/
classtree.py
File metadata and controls
45 lines (30 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
"""
classtree.py Climb inheritance tree using namespace links,
displaying higher superclasses with indentation for height
"""
def classtree(cls, indent):
print('.' * indent + cls.__name__)
for supercls in cls.__bases__:
classtree(supercls, indent + 3)
def instancetree(inst):
print('Tree of %s' % inst)
classtree(inst.__class__, 3)
def selftest():
class A:
pass
class B(A):
pass
class C(A):
pass
class D(B, C):
pass
class E:
pass
class F(D, E):
pass
instancetree(B())
instancetree(D())
instancetree(F())
if __name__ == '__main__':
selftest()