__imul__ does not work !
Uwe Schmitt
uwe.schmitt at procoders.net
Tue Oct 15 11:58:06 EDT 2002
Hi,
I tried to write a class which represents sets of natural numbers.
I wanted to implement A *= B by defining __imul__ as below:
from Numeric import *
class NaturalNumberSet(object):
def __init__(self, orig=None, length=64):
if orig:
length=max(orig)+1
self.indices = zeros((length,),Int0)
if orig:
put(self.indices, orig, 1)
self.length=length
def __imul__(self, other):
ml = min(len(self.indices), len(other.indices))
ha = self.indices[:ml]*other.indices[:ml]
self.indices = ha
self.length=len(ha)
return self
a=NaturalNumberSet([1,2,5])
b=NaturalNumberSet([1,2,5,7])
b *= a
b.__imul__(a)
print b.indices
print a.indices
But the "b*=a" results in
Traceback (most recent call last):
File "bug2.py", line 30, in ?
b *= a
TypeError: can't multiply sequence to non-int
If I outcomment that line, b.__imul__(a) works fine...
Is this a bug ??
Greetings, Uwe
--
Dr. rer. nat. Uwe Schmitt Computer science is no more about Computers,
uwe.schmitt at num.uni-sb.de than astronomy is about telescopes. (Dijkstra)
http://www.procoders.net
More information about the Python-list
mailing list