How to define a division in Python 3.2 ???
see code T1.py
class T1:
def __init__(self,x,y):
self.value = [x,y]
def __mul__(self,other):
tmp = [el * other for el in self.value]
return tmp
def __div__(self,other):
tmp = [el / other for el in self.value]
return tmp
L1 = T1(4,5)
print(L1 * 3)
print(L1 / 3)
see the result with one and the other
C: mp>\Python32\python.exe T1.py
[12, 15]
Traceback (most recent call last):
File “T1.py”, line 13, in <module>
print (l1 / 3)
TypeError: unsupported operand type(s) for /: ‘T1’ and ‘int’
now with 2.6 (or so):
C: mp>python T1.py
[12, 15]
[1, 1]
What is the solution?
EDIT:
looks like one should use truediv in place of div ??!!