Open zhangjun opened 10 months ago
@wrapt @functools.wrap functools.partial
@wrapt
@functools.wrap
functools.partial
def singleton(cls): instances = {} def wrapper(*args, **kwargs): if cls not in instances: instances[cls] = cls(*args, **kwargs) return instances[cls] return wrapper @singleton class Logger: def __init__(self): self.log_file = open("log.txt", "a") def log(self, message): self.log_file.write(f"{message}\n")
After reviewing the code above ,I think you're attempting to receive logs of all instances of same class into a single log.txt file. Please elaborate more on what's the issue you are facing.
装饰器
@wrapt
@functools.wrap
functools.partial