使Daniel Brodie&ŧ039;的单例配方使用关键字参数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使Daniel Brodie&ŧ039;的单例配方使用关键字参数相关的知识,希望对你有一定的参考价值。

The ASPN cookbook has many recipes for singletons in Python. So far, this one
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/412551
has been my favourite, because it is so simple and concise. However, I just ran into a brick wall when I tried to use it with a class that can be initialized with keyword arguments. This is my first draft for a solution to this problem. It's quick and dirty; please give it a glance and leave a comment if you find a problem.
  1. class Singleton(type):
  2. def __init__(self, *args, **kwds):
  3. type.__init__(self, *args, **kwds)
  4. self._instances = {}
  5.  
  6. def __call__(self, *args, **kwds):
  7. sig = args + tuple(sorted(kwds.items()))
  8. if not sig in self._instances:
  9. self._instances[sig] = type.__call__(self, *args, **kwds)
  10. return self._instances[sig]

以上是关于使Daniel Brodie&ŧ039;的单例配方使用关键字参数的主要内容,如果未能解决你的问题,请参考以下文章

检查是否安装了Apache&ŧ039;的modŧu rewrite。

枚举SSID&ŧ039;s

使用TextMate&ŧ039;的tmŧdialog命令创建用户定义的菜单

使用TextMate&ŧ039;s tmŧdialog命令显示警报框

设置UITableView&ŧ039;的页脚文本

&#wordpress中的Include&ŧ039;函数