Closed pablobuenaposada closed 4 years ago
from random import randint class Foobar: _singleton = None
def __init__(self): self.rand = randint(0, 100) self.name = 'hello' @classmethod def get_or_create(cls): if cls._singleton is None: cls._singleton = cls() return cls._singleton def my_method1(self): print(f'{self.name} {self.rand}') @classmethod def my_cls_method1(cls): cls.get_or_create().my_method1()
def my_method1():
foobar = Foobar() foobar.my_method1()
my_method1() my_method1() my_method1() my_method1()
done here 8dde8f4a3641616276713fab7229197222a4a2ac
from random import randint class Foobar: _singleton = None
websocket
def my_method1():
Foobar.my_cls_method1()
my_method1() my_method1() my_method1() my_method1()