replacing one instance with another

manstey manstey at
Mon Mar 26 04:34:51 CEST 2007

Hi, yet again to myself!

I've realised after further testing and reading that I actually need
to do this:

>>>class MyClass(object):
    def __new__(cls,id):
        global dic_myinstances
        if dic_myinstances.has_key(id):
            return dic_myinstances[id]
            dic_myinstances[id] = super(MyClass, cls).__new__(cls, id)
            return dic_myinstances[id]
    def __init__(self,id):
        print id

>>>ins1 = MyClass('xx')
>>>ins2 = MyClass('yy')
>>>ins3 = MyClass('xx')
>>>ins3 is ins1

More information about the Python-list mailing list