Re: Adding methods to an object instance

2009-11-13 Thread Bruno Desthuilliers
lallous a écrit : Hello class __object(object): the convention for reusing reserved words as identifiers is to *suffix* them with a single underscore, ie: class object_(object): # def __getitem__(self, idx): return getattr(self, idx) class __dobject(object): pass x = __ob

Adding methods to an object instance

2009-11-13 Thread lallous
Hello class __object(object): def __getitem__(self, idx): return getattr(self, idx) class __dobject(object): pass x = __object() setattr(x, "0", "hello") print x["0"] y = __dobject(a=1,b=2) setattr(y, "0", "world") #print y["0"] How can I, given an object of instance "__dobject", a