首页 > 代码库 > 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单例设计模式