classes question!
Lei Chen
llchen223 at hotmail.com
Wed Oct 16 16:47:56 EDT 2002
Hello!
What is the error message? I can only guess that the error is coming
from attempts to add a number to an array returned by
RandomArray.random(shape=[])...
Karthikesh Raju <karthik at james.hut.fi> wrote in message news:<2dfzv6y2g4.fsf at synapse.hut.fi>...
> 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