Overloading assignment operator

Carroll, Barry Barry.Carroll at psc.com
Thu Jan 25 13:41:44 EST 2007


> -----Original Message-----
> From: Gabriel Genellina [mailto:gagsl-py at yahoo.com.ar]
> Sent: Tuesday, January 23, 2007 9:24 PM
> To: python-list at python.org
> Subject: Re: Overloading assignment operator
> 
> "Carroll, Barry" <Barry.Carroll at psc.com> escribió en el mensaje
> news:2BBAEE949D384D40A2B851287ADB6A4304595AA4 at eugsrv400.psc.pscnet.com...
> 
> > * ... the assignment operator is used to assign an
> > * object to a name in the current namespace... IOW, you cannot "overload
> > * the assignment operator."
> > (wesley chun)
> This is the key concept, if you want to be able to "see" assignments, you
> should work with a namespace (a dictionary is enough...)
> 
> > * result = property(get_result, set_ result, doc='result of operations')
> >
> > I have tested this using the admittedly simple-minded code snipped
> > below.
<<snip>>
> Notice that you can delete ALL those lines of code, leaving a bare:
> 
> class Aclass: passs
> 
> and you will get EXACTLY the same results. In this case -and this are not
> my
> words- properties are a waste of programmer time, processor time and disk
> space.
> Of course properties are very useful, but when you need to do something
> "more" than just storing and retrieving a single value.
> 
> --
> Gabriel Genellina
Greetings:

Gabriel is right, and my definitions of get_result and set_result were deficient.  Something like this would have been better:

* def get_result(self):
*    do_stuff_before_returning(self)
*    return self.__result
*
* def set_result (self, expression):
*    do_stuff_before_storing(self, expression)
*    self.__result = expression
*

Achim didn't go into the details of his result class(es), so I don't know what the do_stuff_* functions would actually do.  

Sorry for the omission.  

Regards,
 
Barry




More information about the Python-list mailing list