Add Ping's enhanced singleton decorator.

This commit is contained in:
Skip Montanaro 2004-04-08 21:14:34 +00:00
parent 5d8316d6de
commit e675128566
1 changed files with 6 additions and 1 deletions

View File

@ -270,7 +270,12 @@ some examples of use.
::
def singleton(cls):
return cls()
instances = {}
def getinstance():
if cls not in instances:
instances[cls] = cls()
return instances[cls]
return getinstance
class MyClass [singleton]:
...