[Python-Dev] Re: Inplace multiply (original) (raw)
Terry Reedy tjreedy@udel.edu
Tue, 13 May 2003 15:12:50 -0400
- Previous message: [Python-Dev] Inplace multiply
- Next message: [Python-Dev] Re: Inplace multiply
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Jeff Epler" <jepler@unpythonic.net> wrote in message news:20030513183144.GH11289@unpythonic.net...
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
On Win98 2.2.1, cut and paste into interactive window outputs sausages vegetable-style breakfast patty sausages []
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"
Because line above gives TypeError: can't multiply sequence to non-int
print k, o
Maybe something has been 'fixed' since then.
Terry J. Reedy
- Previous message: [Python-Dev] Inplace multiply
- Next message: [Python-Dev] Re: Inplace multiply
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]