Re: test whether 2 objects are equal
- From: Rene Pijlman <reply.in.the.newsgroup@xxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 31 Jan 2006 11:44:22 +0100
Yves Glodt:
>I need to compare 2 instances of objects to see whether they are equal
>or not,
This prints "equal":
class Test(object):
def __init__(self):
self.var1 = ''
self.var2 = ''
def __eq__(self,other):
return self.var1 == other.var1 and self.var2 == other.var2
test1 = Test()
test1.var1 = 'a'
test1.var2 = 'b'
test2 = Test()
test2.var1 = 'a'
test2.var2 = 'b'
if test1 == test2:
print "equal"
else:
print "not equal"
--
René Pijlman
.
- Follow-Ups:
- Re: test whether 2 objects are equal
- From: Yves Glodt
- Re: test whether 2 objects are equal
- References:
- test whether 2 objects are equal
- From: Yves Glodt
- test whether 2 objects are equal
- Prev by Date: Re: finding the intersection of a list of Sets
- Next by Date: Re: Marked-Up Text Viewer for Python/Tkinter
- Previous by thread: test whether 2 objects are equal
- Next by thread: Re: test whether 2 objects are equal
- Index(es):
Relevant Pages
|