首页 > 代码库 > python单例设计模式
python单例设计模式
python的单例模式就是一个类的实例只能自始自终自能创建一次。应用场景比如说数据库的连接池。
()instance (,).name ().instance.instance obj () .instance obj obj duoceshi1 Singleton.get_instance() duoceshi2 Singleton.get_instance() (duoceshi1) (duoceshi2)
运行结果如下:
<__main__.Singleton object at 0x000000000217E4E0>
<__main__.Singleton object at 0x000000000217E4E0>
本文出自 “多测师” 博客,请务必保留此出处http://icestick8586.blog.51cto.com/9867871/1886325
python单例设计模式
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。