Created
December 21, 2011 05:25
-
-
Save Stebalien/1504709 to your computer and use it in GitHub Desktop.
Lazily Evaluated Variable
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
def lazy(func): | |
def get(self): | |
val = func(self) | |
setattr(self, func.func_name, val) | |
return val | |
def set(self, val): | |
setattr(self, func.func_name, val) | |
return property(get, set) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Decorating a method with @lazy will turn it into a property that will replace itself with its return value when evaluated.