[Python-Dev] In-place multiply and new style classes (original) (raw)

Todd Miller jmiller@stsci.edu
Wed, 27 Mar 2002 13:34:17 -0500


Hi,

I'm Todd Miller and I work at the Space Telescope Science Institute on Numarray.
Numarray is STSCI's stab at improving Numeric. This is my first post here.

Today one of the guys in my branch noticed that Numarray's in-place multiply was raising this bizarre exception:

--> a = ones ((5,), Float32) --> a array([1., 1., 1., 1., 1.], type=Float32) --> a *= 62. Traceback (innermost last): File "", line 1, in ? TypeError: can't multiply sequence to non-int

I looked into this for a couple hours and discovered the following:

class test1(object): """A new-style class""" def init(self): pass

def __imul__(self, other):
    print "no luck here!"

t1 = test1() t1 *= 62. Traceback (most recent call last): File "", line 1, in ? TypeError: can't multiply sequence to non-int

Todd

-- Todd Miller jmiller@stsci.edu STSCI / SSG (410) 338 4576