Re: test whether 2 objects are equal
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: test whether 2 objects are equal

From: Yves Glodt <y.glodt@sitasoftware.lu>
Date: Tue Jan 31 2006 - 13:14:13 CET

Rene Pijlman wrote:
> Yves Glodt:
>> I need to compare 2 instances of objects to see whether they are equal
>> or not,
>
> This prints "equal":

thank you!

Have a nice day,
Yves

> 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"
>
Received on Tue Feb 7 20:20:01 2006