How do I overload 'equals'?

Josiah Carlson jcarlson at
Tue Feb 3 04:24:35 CET 2004

> My motivation is to learn about the limitations and capability of Python.

That is easy, Python can't do it.

> We could call it a useless case.

So why bother?  Oh yeah, "to learn about the limitations and capability 
of Python".

> I suspect that building an operator with un-obvious side effects
> is bad programming style.

Of course.  Building a comparison operator that creates arbitrary 
attributes on an argument is one, of many, examples of bad programming 

> It's better to just use a simple function to do the assignment:
> aHouse = superAssign (myHouse)

I don't think that would do what you want.  All that would do is assign 
the name aHouse a reference to whatever is returned by 
superAssign(myHouse).  You aren't modifying what aHouse used to reference.

> I'd still like to build an arbitrary operator though.

It is not possible for all operators.  For a list of those operators 
that you /can/ overload, check the 'operator' module.

  - Josiah

More information about the Python-list mailing list