Re: replacing one instance with another

2007-03-25 Thread Gabriel Genellina
En Sun, 25 Mar 2007 23:34:51 -0300, manstey <[EMAIL PROTECTED]> escribió: > I've realised after further testing and reading that I actually need > to do this: > dic_myinstances={} class MyClass(object): > def __new__(cls,id): > global dic_myinstances > if dic_myinstan

Re: replacing one instance with another

2007-03-25 Thread manstey
Hi, yet again to myself! I've realised after further testing and reading that I actually need to do this: >>>dic_myinstances={} >>>class MyClass(object): def __new__(cls,id): global dic_myinstances if dic_myinstances.has_key(id): return dic_myinstances[id]

Re: replacing one instance with another

2007-03-25 Thread manstey
Hi, I solved it myself! I realised that __new__ creates self prior to init, so this works: >>>dic_myinstances={} >>>class MyClass(object): def __new__(self,id): global dic_myinstances if dic_myinstances.has_key(id): return dic_myinstances[id] else:

replacing one instance with another

2007-03-25 Thread manstey
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 =