Re: test whether 2 objects are equal



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:

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)

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb@xxxxxxxxxxx'.split('@')])"
.



Relevant Pages

  • Re: I am Shocked
    ... I cannot resist sometimes to compare these two languages (as far as I can, ... private double d; ...
    (microsoft.public.dotnet.languages.vc)
  • Re: namespace question
    ... Marc 'BlackJack' Rintsch wrote: ... `b` and `c` are class variables and not instance ...
    (comp.lang.python)
  • Re: namespace question
    ... `b` and `c` are class variables and not instance ... Marc 'BlackJack' Rintsch ...
    (comp.lang.python)
  • Re: is self.var in a class the same as @@var ??
    ... I believe that you are looking for accessors to class instance ... there are no accessors for class variables ... puts "civar b #" ...
    (comp.lang.ruby)