t546.py 533 B

1234567891011121314151617181920212223242526272829303132333435
  1. from time import sleep
  2. class A(object):
  3. def __getattr__(self, name):
  4. sleep(0.001)
  5. print "Getting %s" % name
  6. return name
  7. def __setattr__(self, name, value):
  8. sleep(0.001)
  9. print "Setting %s to %s" % (name, value)
  10. object.__setattr__(self, name, value)
  11. class B(A):
  12. pass
  13. class C(A):
  14. def __getattribute__(self, name):
  15. sleep(0.001)
  16. print "Getting %s early" % name
  17. return "FOO"
  18. b = B()
  19. print "b.x = %s" % b.x
  20. b.x = "BAR"
  21. print "b.x = %s" % b.x
  22. c = C()
  23. print "c.x = %s" % c.x
  24. c.x = "BAR"
  25. print "c.x = %s" % c.x