replacing one instance with another

manstey manstey at csu.edu.au
Sun Mar 25 21:38:34 EDT 2007


Hi,
I'm not sure why this doesn't work:

>>>dic_myinstances={}

>>>class MyClass(object):
    def __init__(self, id):
         global dic_myinstances
         if dic_myinstances.has_key(id):
              self = dic_myinstances[id]
         else:
              dic_myinstances[id] = self

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

Why isn't ins3 the same as ins1? How can I get this to work?

thanks




More information about the Python-list mailing list