python delegate (wrapper)


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # learning python 3rd edition
  2. # page 528
  3.  
  4. class Delegate(object):
  5. def __init__(self, wrapper):
  6. self.wrapper = wrapper
  7.  
  8. def __getattr__(self, attribute):
  9. print "working on"
  10. return getattr(self.wrapper, attribute)
  11.  
  12.  
  13.  
  14.  
  15. a_list = Delegate([1,2])
  16.  
  17. a_list.append(4)
  18. working on

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.