overriding equals operation
Nobody
nobody at nowhere.com
Tue Oct 16 13:31:45 EDT 2012
On Tue, 16 Oct 2012 08:51:46 -0500, Pradipto Banerjee wrote:
> I am trying to define class, where if I use a statement a = b, then
> instead of "a" pointing to the same instance as "b", it should point to a
> copy of "b", but I can't get it right.
It cannot be done.
Name binding ("variable = value") is a language primitive; it is not
delegated to the object on the LHS (if there even is one; the name doesn't
have to exist at the point that the statement is executed).
You'll have to change the syntax to something which is delegated to
objects, e.g. "a[:] = b" will call "a.__setitem__(slice(None), b)"
More information about the Python-list
mailing list