KraftDiner wrote: > Hi I have a list of Ojbects... I want to change one of the objects in > the list for a new object.... > How do I replace an existing object with a new one and maintain the > list order.. > > This is what I have... > > def setAttribute(self, desc, value): > n = anObject(desc, value) > for o in self.Objects: > if o.getDescription() == desc: > self.Objects.replace(o, n) #Replace o with n? > return > self.Objects.append(n) > > It's the replace in place that I don't know how to do... > There are a number of ways. I suspect the simplest would be (untested):
def setAttribute(self, desc, value): n = anObject(desc, value) for i, o in enumerate(self.Objects): if o.getDescription() == desc: self.Objects[i] = n return self.Objects.append(n) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list