Singleton and C extensions
Scott David Daniels
scott.daniels at acm.org
Fri Nov 25 14:00:13 EST 2005
Emmanuel Briot wrote:
> I am participating in the development of a GPL IDE
> https://libre2.adacore.com/gps/
> I am not really good at python, but I was trying to implement the
> singleton design pattern in C, so that for instance calling the constructor
> ed = Editor ("foo")
Fredrik's advice is probably better, but if you must:
class Editor(object):
table = {}
def __new__(klass, name):
try:
return klass.table[name]
except KeyError:
klass.table[name] = super(Singled, klass).__new__(klass)
return klass.table[name]
--Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list