Skip to content

Instantly share code, notes, and snippets.

@sloria sloria/lazy_init.py
Last active Aug 13, 2019

Embed
What would you like to do?
# Better
class Person:
def __init__(self, name, occupation):
self.name = name
self.occupation = occupation
self._relatives = None
@property
def relatives(self):
if self._relatives is None:
self._relatives = ... # Get all relatives
return self._relatives
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.