[Tutor] classes question

Magnus Lycka magnus@thinkware.se
Wed Oct 23 04:39:10 2002


At 10:26 2002-10-23 +0300, Karthikesh Raju wrote:
>i think this is quite close. The only issue here is
> >>>  result =3D source(self.k, self.n, self.type)
>This generates unnecessary data which is then replaced with the actual
>data. Any methods to reasonably do it otherways.

Ok. add a parameter with default value "data =3D None"
to sources.__init__. Then use a construct like this
in the body of __init__:

if data is not None:
     self.data =3D data
else:
     <whatever you do today.>

I think you understand how to adapt __add__ to that...

>Actually, since i come from a non-classy world, is my approach right.

I might be more critical if I knew more about
the mathematics you are involved in, but in
general it seems reasonable to me.

I'm not an expert in performance for heavy calculations though.
You'll probably get more informed advice somewhere else. I
was about to suggest the python-numerics mailing list, but that
seems dead. Let's see... Aha, numpy-discussion is the place. See
http://www.geocrawler.com/lists/3/SourceForge/1329/0



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se