Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Created April 7, 2014 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-martin/10014626 to your computer and use it in GitHub Desktop.
Save chris-martin/10014626 to your computer and use it in GitHub Desktop.
class LazyInit(object):
def __init__(self, cls, *args, **kwargs):
self.wrapped = None
self.cls = cls
self.args = args
self.kwargs = kwargs
def __getattr__(self, key):
if self.wrapped is None:
self.wrapped = self.cls(*self.args, **self.kwargs)
return getattr(self.wrapped, key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment