test.py 393 B

123456789101112131415161718192021222324
  1. class B(object):
  2. def fn(self):
  3. print 'B fn'
  4. def __init__(self):
  5. print "B INIT"
  6. class A(object):
  7. def fn(self):
  8. print 'A fn'
  9. def __new__(cls,a):
  10. print "NEW", a
  11. if a>10:
  12. return super(A, cls).__new__(cls)
  13. return B()
  14. def __init__(self,a):
  15. print "INIT", a
  16. a1 = A(5)
  17. a1.fn()
  18. a2=A(20)
  19. a2.fn()