Lazy Descriptors


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



Copy this code and paste it in your HTML
  1. class LazyProperty(object):
  2.  
  3. def __init__(self, func):
  4. self._func = func
  5. self.__name__ = func.__name__
  6. self.__doc__ = func.__doc__
  7.  
  8. def __get__(self, obj, klass=None):
  9. if obj is None: return None
  10. result = obj.__dict__[self.__name__] = self._func(obj)
  11. return result

URL: http://blog.pythonisito.com/2008/08/lazy-descriptors.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.