【自用】Python 单例模式(使用模块简单实现)

 Singleton__.py

# 代码保存在文件 Singleton__.py

class Singleton(object):
    g_map = []

    def __init__(self):
        pass


__instance = Singleton()


def instance():
    return __instance

使用时:

import Singleton__

slt1 = Singleton__.instance()
slt2 = Singleton__.instance()

    PS:自用的  不做解释                        作者:一个吃货帅锅    

猜你喜欢

转载自my.oschina.net/kilosnow/blog/1802407