Skip to content

Instantly share code, notes, and snippets.

@vmihailenco
Created July 2, 2011 08:29
Show Gist options
  • Save vmihailenco/1059858 to your computer and use it in GitHub Desktop.
Save vmihailenco/1059858 to your computer and use it in GitHub Desktop.
cached_property.py
class cached_property(object):
def __init__(self, func):
self.func = func
def __get__(self, obj, type=None):
if obj is None:
return self
obj.__dict__[self.func.__name__] = value = self.func(obj)
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment