overriding = operator

Anton Mellit mellit at gmail.com
Wed Apr 23 10:36:08 CEST 2008


On Apr 22, 3:54 pm, Paul McGuire <pt... at austin.rr.com> wrote:
> 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?
>
> > Anton
>
> 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.
>
> -- Paul

Great idea! It conflicts with 'left shift in place', which i also
need, but '=' seems more important.

Anton



More information about the Python-list mailing list