Re: multi-Singleton-like using __new__

2008-02-08 Thread Freek Dijkstra
J Peyret wrote: > >>> class RDFObject(object): > > ... cache ={} > ... isInitialized = False > ... def __new__(cls,uri,*args,**kwds): > ... try: > ... return cls.cache[uri] > ... except KeyError: > ... print "cache miss" > ... res = c

multi-Singleton-like using __new__

2008-02-08 Thread Freek Dijkstra
Is there a best practice on how to override __new__? I have a base class, RDFObject, which is instantiated using a unique identifier (a URI in this case). If an object with a given identifier already exists, I want to return the existing object, otherwise, I want to create a new object and add thi