GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — StarterLearningPython/python3code/chapter04/singleton.py at master · QiKang556/StarterLearningPython Expand file tree/ Copy pathsingleton.pyMore file actions 20 lines (17 loc) · 354 Bytes / Copy pathsingleton.pyFile metadata and controls20 lines (17 loc) · 354 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #coding:utf-8 ''' filename: singleton.py ''' class Singleton: _instance = None def __new__(cls, *args, **kwargs): if not cls._instance: cls._instance = super().__new__(cls) return cls._instance class MyClass(Singleton): a = 1 x = MyClass() y = MyClass() print(x) print(y) print("x is y: ", x is y) |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |