会员
周边
新闻
博问
闪存
众包
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
代码改变世界
Cnblogs
Dashboard
Login
Home
Contact
Gallery
Subscribe
RSS
AIF
随笔档案-2019年10月
python三种方法创建单例模式
2019-10-24 11:08 by AIF, 330 阅读,
收藏
,
摘要: # 方法一,装饰器 from functools import wraps def single_instance(cls): """装饰器实现单例模式,装饰器相当于把类给包了起来,强制返回一个对象""" _instance = None @wraps(cls) def wrapper(*args, **kwargs): nonlocal _instance if _instance is Non
阅读全文
0 Comment
About