Path: csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: Python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.031 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'class,': 0.07; 'completeness': 0.07; 'try:': 0.07; '"a"': 0.09; 'behave': 0.09; 'construed': 0.09; 'currently,': 0.09; 'objects.': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'buy,': 0.16; 'copy(self):': 0.16; 'operation.': 0.16; 'solicitation': 0.16; 'instance': 0.17; '>>>': 0.18; 'define': 0.20; 'trying': 0.21; 'cc:2**0': 0.23; 'purposes': 0.23; 'statement': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; '----': 0.27; 'right.': 0.27; 'accuracy': 0.27; 'reflect': 0.27; 'comparison': 0.29; '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; 'likely': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'self': 0.34; 'thanks': 0.34; 'from:addr:googlemail.com': 0.35; 'received:209.85': 0.35; 'really': 0.36; 'but': 0.36; 'wanted': 0.36; 'should': 0.36; 'two': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'advice': 0.39; 'instead': 0.39; 'performance': 0.39; 'where': 0.40; 'materials': 0.61; '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; '8bit%:70': 0.91; 'investor': 0.93 Newsgroups: comp.lang.python Date: Tue, 16 Oct 2012 21:16:01 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=123.192.32.215; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 123.192.32.215 MIME-Version: 1.0 Subject: Re: overriding equals operation From: 88888 Dihedral To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: "Python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 117 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350447365 news.xs4all.nl 6872 [2001:888:2000:d::a6]:54763 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31459 Pradipto Banerjee=E6=96=BC 2012=E5=B9=B410=E6=9C=8816=E6=97=A5=E6=98=9F=E6= =9C=9F=E4=BA=8CUTC+8=E4=B8=8B=E5=8D=889=E6=99=8259=E5=88=8605=E7=A7=92=E5= =AF=AB=E9=81=93=EF=BC=9A > I am trying to define class, where if I use a statement a =3D b, then ins= tead of "a" pointing to the same instance as "b", it should point to a copy= of "b", but I can't get it right. >=20 >=20 >=20 > Currently, I have the following: >=20 >=20 >=20 > ---- >=20 >=20 >=20 > class myclass(object): >=20 > def __init__(self, name=3D'') >=20 > self.name =3D name >=20 >=20 >=20 > def copy(self): >=20 > newvar =3D myclass(self.name) >=20 > return newvar >=20 >=20 >=20 > def __eq__(self, other): >=20 > if instance(other, myclass): >=20 > return self =3D=3D other.copy() >=20 > return NotImplemented >=20 > ---- >=20 >=20 >=20 > Now if I try: >=20 >=20 >=20 > >>> a=3Dmyclass() >=20 > >>> a.name =3D 'test' >=20 > >>> b=3Da >=20 What you really want is b=3Da.copy()=20 not b=3Da to disentangle two objects. __eq__ is used in the comparison operation.=20 =20 > >>> b.name >=20 > 'test' >=20 > >>> b.name =3D 'test2' >=20 > >>> a.name >=20 > 'test2' >=20 >=20 >=20 > I wanted b=3Da to make a new copy of "a", but then when I assigned b.name= =3D 'test2', even a.name became 'test2'. >=20 >=20 >=20 > How can I rectify my code to make the __eq__() behave like copy()? >=20 >=20 >=20 > Thanks >=20 >=20 >=20 >=20 >=20 > This communication is for informational purposes only. It is not intende= d to be, nor should it be construed or used as, financial, legal, tax or in= vestment 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 Inves= tment advisor. Any offer or solicitation of an investment in any of the Fu= nds may be made only by delivery of such Funds confidential offering materi= als to authorized prospective investors. An investment in any of the Funds= is not suitable for all investors. No representation is made that the Fun= ds will or are likely to achieve their objectives, or that any investor wil= l or is likely to achieve results comparable to those shown, or will make a= ny profit at all or will be able to avoid incurring substantial losses. Pe= rformance results are net of applicable fees, are unaudited and reflect rei= nvestment of income and profits. Past performance is no guarantee of futur= e results. All financial data and other information are not warranted as to= completeness or accuracy and are subject to change without notice. >=20 >=20 >=20 > Any comments or statements made herein do not necessarily reflect those o= f Ada Investment Management LP and its affiliates. This transmission may co= ntain information that is confidential, legally privileged, and/or exempt f= rom 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 st= rictly prohibited. If you received this transmission in error, please immed= iately contact the sender and destroy the material in its entirety, whether= in electronic or hard copy format.