operator over loading

Diez B. Roggisch deetsNOSPAM at web.de
Sat May 22 10:44:01 EDT 2004


Anand K Rayudu wrote:

> Hi all,
> 
> I have defined q python class and want to know if i can over load '='
> operator.

No you can't - that stems from the fact that assignment in python means that
a value is bound to <name>, not that there is made a copy of that value
stored into some space referred to by <name>, as it is done it C/C++. Think
of variables as references. There is also no &= operator in C++ to
overload.

> Now the problem is cos(c), sin(b) creates new objects, which are used
> for multiplication.
> This again generates a new object,
> What i want to do it automatically delete all intermediate objects.
> except the one assigned to a.
> currently i am deleteing c object in __del__
> So once I reassing some thing else to a that is also getting deleted.
> So what i want to do is once i assign it to a variable, i want to set
> flag so that i won;t delete it in _del_

Why do you care?  Let pythons GC do the job for you.

It looks like you try to impose C++ thinking on python here. While thats
understandable, its never good to try to stick to the idioms of one
language in anotherone - you miss the nice differences then :)

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list