Created
April 7, 2014 03:57
-
-
Save chris-martin/10014626 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 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