How do I overload 'equals'?

Equis Uno ir4u4 at yahoo.com
Mon Feb 2 05:52:00 EST 2004


Hi there,

I just figured out how to use __add__() to overload the "+" operator
for objects of a class.

According to googel queries, I see other functions available to me for
overloading other operators:

__mul__(), __sub__(), ...

I was hoping to overload "=" or use some string to do assignment with
side effects.

For example,

obj1 = ClassX('green')
obj2 = ClassX('red')

obj1 superEqual obj2

I'd like to be able to control the behavior of the superEqual operator
such that it does assignment with side effects.

For example, maybe it would do this:

obj = obj2
incrementEqualityCounter()
addAuditRecordToDB()

How do I do this in Python?

-moi



More information about the Python-list mailing list