Posted By

silviud on 07/18/10


Tagged

python patterns design delegation


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

saman


python delegate (wrapper)


 / Published in: Python
 

  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  

You need to login to post a comment.