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 - 16:07:54 CET

bruno at modulix wrote:
> Yves Glodt wrote:
>> Hello,
>>
>>
>> I need to compare 2 instances of objects to see whether they are equal
>> or not, but with the code down it does not work (it outputs "not equal")
>>
>>
>> #!/usr/bin/python
>>
>> class Test:
>> var1 = ''
>> var2 = ''
>
> Take care, this creates two *class* variables var1 and var2. For
> *instance* variables, you want:

Thanks for making me aware. I'll have to read more about classes in
python... ( As you can see I'm still new to it ;-)

btw, this is the best list I've ever joined, very helpful and nice ppl.

Have a nice day!
Yves

> class Test:
> def __init__(self, var1='', var2=''):
> self.var1 = var1
> self.var2 = var2
>
>
>> test1 = Test()
>> test1.var1 = 'a'
>> test1.var2 = 'b'
>
> This creates instances variables var1 and var2 for test1 (shadowing
> class variables).
>
> (snip the rest, see other posts in this thread)
>
Received on Tue Feb 7 20:22:06 2006