classes question!

Karthikesh Raju karthik at james.hut.fi
Wed Oct 16 08:48:27 EDT 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 at 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
-----------------------------------------------------------------------



More information about the Python-list mailing list