摘要: 一、使用__new__方法可以实现单例模式: TestClass类实例化时,因为自身的__new__方法没有重写,默认会调用其父类,也就是SingleTon的__new__方法。而SingleTon的__new__方法重写为仅当自身没有instance属性时才会返回一个类实例,从而确保了仅生成1个实 阅读全文
posted @ 2018-02-25 17:25 右威卫大将军 阅读(181) 评论(0) 推荐(0) 编辑
摘要: import functools def log(text): if isinstance(text, str): def decorator(func): @functools.wraps(func) def wrapper(*args, **kw): func(*args, **kw) prin 阅读全文
posted @ 2018-02-25 09:42 右威卫大将军 阅读(163) 评论(0) 推荐(0) 编辑