Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31423

Re: overriding equals operation

From Nobody <nobody@nowhere.com>
Subject Re: overriding equals operation
Date 2012-10-16 18:31 +0100
Message-Id <pan.2012.10.16.17.31.46.151000@nowhere.com>
Newsgroups comp.lang.python
References <mailman.2273.1350395930.27098.python-list@python.org>
Organization Zen Internet

Show all headers | View raw


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)"

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

overriding equals operation Pradipto Banerjee <pradipto.banerjee@adainvestments.com> - 2012-10-16 08:51 -0500
  Re: overriding equals operation Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-16 16:07 +0200
  Re: overriding equals operation Nobody <nobody@nowhere.com> - 2012-10-16 18:31 +0100
  Re: overriding equals operation 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-16 21:16 -0700
    Re: overriding equals operation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-17 09:14 +0100
  Re: overriding equals operation 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-16 21:16 -0700

csiph-web