uioziaremwpl at spammotel.com
Sun Jun 17 10:16:41 CEST 2001
On Sun, 17 Jun 2001, Roman Suzi wrote:
> On Sat, 16 Jun 2001, Neil Macneale wrote:
> >I am creating a colored stringbuffer class, and I want to append words to
> >the buffer with the '+=' operator. Ex:
> >>>>csb = CSB("INIT STRING")
> >>>>csb += "Hello"
> >>>>print csb
> >INIT STRINGHello
> >would be the desired effect. I can't seem to find anything in the lib
> >docs about overloading that operator though. Am I looking in the wrong
> >place? It is also important that a new object is NOT created every time
> >the operator is used, because that would be a waste.
> class CSB:
> def __iadd__(self, x):
> self._string += x
Don't forget the "return self" or similar.
More information about the Python-list