求问 这个模块是什么意思,一直看不懂。初学python求指教啊
def singleton(cls):instances = {}
def get_instance():
if cls not in instances:
instances[cls] = cls()
return instances[cls]
return get_instance
@singleton
class Mylogger:
_fpath = 'mokey.log'
_file = None
def __init__(self):
self._file = open(self._fpath, mode='w',encoding = 'utf-8')
print("初始化成功")
def write(self, string):
if self._file:
self._flie.write(string)
print("打印成功了")