Andre Engels wrote:
> Is it possible to define a class in such a way, that if twice an
> object is made with the same initialization parameters, the same
> object is returned in both cases?
>
Use a "factory" function, and store a dictionary of instances as a class
property:
class myObj(object):
instances = {}
def __init__(self,a):
# the rest of your code
def makemyObj(a):
if a in myObj.instances:
return myObj.instances[a]
else:
new_instance = myObj(a)
myObj.instances[a] = new_instance
return new_instance
[snip]
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor