Posted By

jfred on 08/31/08


Tagged

Decorator lazy


Versions (?)

Lazy Descriptors


 / Published in: Python
 

URL: http://blog.pythonisito.com/2008/08/lazy-descriptors.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

Report this snippet  

You need to login to post a comment.