fan9zq
Results
1
comments of
fan9zq
## 单例模式中的装饰器版本有bug 当被装饰的类中 `__init__()` 方法有初始化参数时,将报 `TypeError` 异常。建议更改为: ```python def singleton(cls): instances = {} def getinstance(*args, **kw): if cls not in instances: instances[cls] = cls(*args, **kw) return instances[cls] return getinstance ```