Created
May 26, 2014 05:09
-
-
Save luoyetx/cd0c1cd87bbab7134196 to your computer and use it in GitHub Desktop.
cached_property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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