Properties - when and why

Alex Martelli aleax at aleax.it
Mon Jul 8 18:11:58 EDT 2002


Arthur Siegel wrote:

> Alex writes -
> 
>>The obvious solution for this case is to keep your original
>>get_V method intact and to code V_homogeneous the simple way:
> 
>>def V_homogenous(self):
>>    V = self.V
>>   return array((V.x,V.y,V.z,1.))
> 
> Thanks for the reply, and sorry for the various careless idiocies in my
> post.

You're welcome, and, no problem.

> But your suggestion is exactly what I concluded to do in my own code
> until I thought I concluded - and this is the gist of my question - that
> even with the
> syntax you suggest I was making now 4 calls to the vector subtract
> calculation -
> one for V= self.V and one each time I called for an attribute of V.
> 
> If I am wrong there - my problem essentially goes away. I was doing it in

Yep, it goes away, because you're wrong.  Local variable V is bound
to the value returned by self.V and stays bound to that value -- no
further calls (it would require deep magic indeed to provoke such calls:-).

> a context of my code where there are many interrelationships and I may
> have misintepreted what I was seeing.
> 
> Are you in fact saying that your suggested solution avoids multiple calls
> to the calculation that determines the value of self.V?

Right.


Alex




More information about the Python-list mailing list