Created
September 23, 2015 08:33
-
-
Save pimiento/c5074b5a11c3704e8c06 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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