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


Groups > comp.lang.python > #31402

overriding equals operation

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <pradipto.banerjee@adainvestments.com>
X-Original-To Python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.087
X-Spam-Evidence '*H*': 0.83; '*S*': 0.00; 'class,': 0.07; 'completeness': 0.07; 'try:': 0.07; '"a"': 0.09; 'behave': 0.09; 'construed': 0.09; 'currently,': 0.09; 'def': 0.10; 'buy,': 0.16; 'copy(self):': 0.16; 'solicitation': 0.16; 'instance': 0.17; '>>>': 0.18; 'define': 0.20; 'to:name:python-list@python.org': 0.20; 'trying': 0.21; 'purposes': 0.23; 'statement': 0.23; '----': 0.27; 'right.': 0.27; 'accuracy': 0.27; 'reflect': 0.27; 'statements': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; '(including': 0.30; 'law.': 0.30; 'code': 0.31; 'point': 0.31; 'comments': 0.33; 'material': 0.33; 'profit': 0.33; 'substantial': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; "can't": 0.34; 'self': 0.34; 'thanks': 0.34; 'but': 0.36; 'wanted': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'data': 0.37; 'received:10': 0.38; 'advice': 0.39; 'instead': 0.39; 'performance': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'materials': 0.61; 'received:network': 0.61; 'received:216': 0.62; 'interest': 0.62; 'necessarily': 0.63; 'skip:n 10': 0.63; 'information': 0.63; 'offering': 0.64; 'results': 0.65; 'management': 0.65; 'notified': 0.65; 'offer': 0.65; 'subject': 0.66; 'reliance': 0.66; 'investment': 0.67; 'fund': 0.67; 'income': 0.67; 'contact': 0.68; 'funds': 0.78; 'disclosure,': 0.78; "'test'": 0.84; 'comparable': 0.84; 'investor': 0.93
X-Env-Sender pradipto.banerjee@adainvestments.com
X-Msg-Ref server-3.tower-160.messagelabs.com!1350395525!11769206!4
X-Originating-IP [216.166.12.97]
X-StarScan-Received
X-StarScan-Version 6.6.1.3; banners=-,-,-
X-VirusChecked Checked
From Pradipto Banerjee <pradipto.banerjee@adainvestments.com>
To "Python-list@python.org" <Python-list@python.org>
Date Tue, 16 Oct 2012 08:51:46 -0500
Subject overriding equals operation
Thread-Topic overriding equals operation
Thread-Index Ac2rpWHfJk6oKsEAROefKNATxvpDJQ==
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-cr-hashedpuzzle AJh4 ALxa BrXQ CoAg Eauv GEkg GFM6 GOtL G5/Z H2RY Jhal KaWo Ka0W Kety LlUr L/q/; 1; cAB5AHQAaABvAG4ALQBsAGkAcwB0AEAAcAB5AHQAaABvAG4ALgBvAHIAZwA=; Sosha1_v1; 7; {50C73C6E-758F-4CCA-9127-72AEE5041A33}; cAByAGEAZABpAHAAdABvAC4AYgBhAG4AZQByAGoAZQBlAEAAYQBkAGEAaQBuAHYAZQBzAHQAbQBlAG4AdABzAC4AYwBvAG0A; Tue, 16 Oct 2012 13:51:46 GMT; bwB2AGUAcgByAGkAZABpAG4AZwAgAGUAcQB1AGEAbABzACAAbwBwAGUAcgBhAHQAaQBvAG4A
x-cr-puzzleid {50C73C6E-758F-4CCA-9127-72AEE5041A33}
acceptlanguage en-US
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2273.1350395930.27098.python-list@python.org> (permalink)
Lines 66
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350395930 news.xs4all.nl 6850 [2001:888:2000:d::a6]:45251
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31402

Show key headers only | View raw


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.

Currently, I have the following:

----

class myclass(object):
        def __init__(self, name='')
                self.name = name

        def copy(self):
                newvar = myclass(self.name)
                return newvar

        def __eq__(self, other):
                if instance(other, myclass):
                        return self == other.copy()
                return NotImplemented
----

Now if I try:

>>> a=myclass()
>>> a.name = 'test'
>>> b=a
>>> b.name
'test'
>>> b.name = 'test2'
>>> a.name
'test2'

I wanted b=a to make a new copy of "a", but then when I assigned b.name = 'test2', even a.name became 'test2'.

How can I rectify my code to make the __eq__() behave like copy()?

Thanks


 This communication is for informational purposes only. It is not intended to be, nor should it be construed or used as, financial, legal, tax or investment advice or an offer to sell, or a solicitation of any offer to buy, an interest in any fund advised by Ada Investment Management LP, the Investment advisor.  Any offer or solicitation of an investment in any of the Funds may be made only by delivery of such Funds confidential offering materials to authorized prospective investors.  An investment in any of the Funds is not suitable for all investors.  No representation is made that the Funds will or are likely to achieve their objectives, or that any investor will or is likely to achieve results comparable to those shown, or will make any profit at all or will be able to avoid incurring substantial losses.  Performance results are net of applicable fees, are unaudited and reflect reinvestment of income and profits.  Past performance is no guarantee of future results. All financial data and other information are not warranted as to completeness or accuracy and are subject to change without notice.

Any comments or statements made herein do not necessarily reflect those of Ada Investment Management LP and its affiliates. This transmission may contain information that is confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is strictly prohibited. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format.

Back to comp.lang.python | Previous | NextNext 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