Skip to content

Instantly share code, notes, and snippets.

@luoyetx
Created May 26, 2014 05:09
Show Gist options
  • Save luoyetx/cd0c1cd87bbab7134196 to your computer and use it in GitHub Desktop.
Save luoyetx/cd0c1cd87bbab7134196 to your computer and use it in GitHub Desktop.
cached_property
class cached_property(object):
"""A cached property only computed once
"""
def __init__(self, func):
self.func = func
def __get__(self, obj, cls):
if obj is None: return self
value = obj.__dict__[self.func.__name__] = self.func(obj)
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment