[Python-Dev] Inplace multiply (original) (raw)

Jeff Epler jepler@unpythonic.net
Tue, 13 May 2003 13:31:45 -0500


There must be something more to your problem than what you described.

The following executes just fine for me (ditto if NewKoke is a subclass of object instead of list, and no matter whether I define getitem or not [a guess based on your remark about 'multiply a sequence']):

$ python dubois.py sausages vegetable-style breakfast patty sausages vegetable-style breakfast patty

class Klassic: def imul(self, other): return "sausages" def getitem(self, i): return None

class NewKoke(list): def imul(self, other): return "vegetable-style breakfast patty" def getitem(self, i): return None

k = Klassic() o = NewKoke()

k *= 1 o *= 1

print k, o

k = Klassic() o = NewKoke()

k *= "spam" o *= "spam"

print k, o