-
-
Save rightfold/4503306f6cf097669a8e to your computer and use it in GitHub Desktop.
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 lazy: | |
__slots__ = ('_thunk', '_value') | |
def __init__(self, thunk): | |
self._thunk = thunk | |
@property | |
def value(self): | |
if not hasattr(self, '_value'): | |
self._value = self._thunk() | |
delattr(self, '_thunk') | |
return self._value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment