[Python-Dev] Inplace multiply by float
Todd Miller
jmiller@stsci.edu
Mon, 15 Apr 2002 17:54:07 -0400
This is a multi-part message in MIME format.
--------------020100030200060800050708
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hi,
Forgive me for asking this question again, but when I import the
following from "example.py":
class test1(object):
def __init__(self):
object.__init__(self)
def __imul__(self, other):
print "no luck here!"
class test2:
def __imul__(self, other):
print "cool!"
t = test1()
u = test2()
t *= 1.0
u *= 1.0
The following happens:
Python 2.3a0 (#6, Apr 15 2002, 17:34:04)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import example
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "example.py", line 18, in ?
t *= 1.0
TypeError: can't multiply sequence to non-int
>>>
I take this to mean that python does not (currently) support inplace
multiply by
floats for new style classes. Is this a bug? A permanent limitation?
Regards,
Todd
--
Todd Miller jmiller@stsci.edu
STSCI / SSG (410) 338 4576
--------------020100030200060800050708
Content-Type: text/plain;
name="example.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="example.py"
class test1(object):
def __init__(self):
object.__init__(self)
def __imul__(self, other):
print "no luck here!"
class test2:
def __imul__(self, other):
print "cool!"
t = test1()
u = test2()
t *= 1.0
u *= 1.0
--------------020100030200060800050708--