Created
June 25, 2020 17:03
-
-
Save guihao-liang/7f2f58eb426b8d23bdff541dbbfa43d2 to your computer and use it in GitHub Desktop.
pythonic design patterns
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 Example(object): | |
| """A singleton not thread safe | |
| """ | |
| _instance = None | |
| @classmethod | |
| def instance(cls): | |
| if cls._instance is None: | |
| cls._instance = cls.__new__(cls) | |
| cls._instance._attrs = [] | |
| return cls._instance | |
| def __init__(self): | |
| raise RuntimeError('This is a singleton, call instance() instead.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment