Skip to content

Instantly share code, notes, and snippets.

@jmcarp
Created July 28, 2014 21:59
Show Gist options
  • Save jmcarp/655aa2ad4f4eb431622b to your computer and use it in GitHub Desktop.
Save jmcarp/655aa2ad4f4eb431622b to your computer and use it in GitHub Desktop.
class _Bar(object):
pass
class Foo(object):
def __init__(self):
self._bar = None
@property
def bar(self):
if self._bar is None:
print('Instantiating a `_Bar`')
self._bar = _Bar()
return self._bar
> foo = Foo()
> foo.bar
Instantiating a `_Bar`
<_Bar object @...>
> foo.bar
<_Bar object @...>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment