[Tutor] classes question
Karthikesh Raju
karthik@james.hut.fi
Tue Oct 22 14:35:01 2002
Hi,
i just started to write a class, when i was struck:
i did something like:
import Numeric
import RandomArray
class source:
def __init__(self, k=1,n=1,type='uniform'):
self.k = k
self.n = n
self.type = type
if type == 'uniform':
self.data = RandomArray.random([K,N])
Now i want to do __add__ overloading and the function should return an
another source
i did:
def __add__(self, other):
return source(self.data + other)
i keep getting errors when i try x+5; x is an object of type source.
i want to be able to implement
x+5
x+y (x,y are of type sources)
and other non source types should be converted to source types.
Any help is great,
thankx in advance,
karthik
-----------------------------------------------------------------------
Karthikesh Raju, email: karthik@james.hut.fi
Researcher, http://www.cis.hut.fi/karthik
Helsinki University of Technology, Tel: +358-9-451 5389
Laboratory of Comp. & Info. Sc., Fax: +358-9-451 3277
Department of Computer Sc.,
P.O Box 5400, FIN 02015 HUT,
Espoo, FINLAND
-----------------------------------------------------------------------