标签:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def singleton(cls, *args, **kw):
instances = {}
def _singleton():
if cls not in instances:
instances[cls] = cls(*args, **kw)
return instances[cls]
return _singleton
#!/usr/bin/env python
# -*- coding: utf-8 -*-
@singleton
class Config:
def __init__(self):
pass
def test(self):
pass
#!/usr/bin/env python
# -*- coding: utf-8 -*-
config = Config()
config.test()
...
标签:
原文地址:http://blog.csdn.net/kongxx/article/details/50538927