1 #!/usr/bin/env python 2 3 class B: 4 def __init__(self, y): 5 self.y = y 6 def m(self, x): 7 return x 8 9 class A: 10 c1 = B 11 m1 = B.m 12 def __init__(self, b): 13 self.c2 = B 14 self.m2 = B.m 15 self.c3 = b 16 self.m3 = b.m 17 18 b = B(789) 19 a = A(b) 20 result_123 = A.m1(b, 123) # A.m1 is unbound 21 result_234 = a.m1(b, 234) # a.m1 is unbound 22 result_345 = a.m2(b, 345) # a.m2 is unbound 23 result_456 = a.m3(456) # a.m3 is bound to b 24 25 b1 = A.c1(678) # A.c1 is just a reference to B 26 result_678 = b1.y 27 b2 = a.c1(567) # a.c1 is just a reference to B 28 result_567 = b2.y 29 b3 = a.c2(765) # a.c2 is just a reference to B 30 result_765 = b3.y 31 32 # vim: tabstop=4 expandtab shiftwidth=4