Skip to content

Instantly share code, notes, and snippets.

@pimiento
Created September 23, 2015 08:33
Show Gist options
  • Select an option

  • Save pimiento/c5074b5a11c3704e8c06 to your computer and use it in GitHub Desktop.

Select an option

Save pimiento/c5074b5a11c3704e8c06 to your computer and use it in GitHub Desktop.
class OnlyOnce(object):
class __OnlyOnce(object):
def __init__(self):
with open('/tmp/test.txt', 'a') as t:
t.write("new line\n")
def lines(self):
with open('/tmp/test.txt', 'r') as t:
return t.readlines()
instance = None
def __new__(cls):
if OnlyOnce.instance is None:
OnlyOnce.instance = OnlyOnce.__OnlyOnce()
return OnlyOnce.instance
def __getattr__(self, name):
return getattr(self.instance, name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment