overriding = operator
ptmcg at austin.rr.com
Tue Apr 22 15:54:12 CEST 2008
On Apr 22, 8:47 am, "Anton Mellit" <mel... at gmail.com> wrote:
> I need something like
> 'overriding' =, which is impossible, but I look for a systematic
> approach to do something instead. It seems there are two ways to do
> what I need:
> 1. Implement a method 'assign' which generates the corresponding code
> to store value:
> z.assign(x + y)
> 2. Do the same as 1., but via property set methods. For example, this
> would look cleaner:
> z.value = x + y
> Which of these is preferrable? Does anyone know any alternative ways?
If you are willing to accept '<<=' as meaning 'assign to existing'
instead of 'left shift in place', you can override this operator using
the __ilshift__ method.
We used this technique in C++/CORBA code back in the 90's to "inject"
values into CORBA::Any variables.
More information about the Python-list