Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:21
Show Gist options
  • Save rightfold/4503306f6cf097669a8e to your computer and use it in GitHub Desktop.
Save rightfold/4503306f6cf097669a8e to your computer and use it in GitHub Desktop.
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