test whether 2 objects are equal

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Tue Jan 31 19:13:39 EST 2006


Yves Glodt a écrit :
> bruno at modulix wrote:
> 
>> Yves Glodt wrote:
>>
(snip)

>>> #!/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 ;-)

I don't remember what's your background, but if you come from 
C++/Java/..., then yes, definitevely, you need to learn more about 
Python's object model. The class variable/instance variable confusion is 
a common gotcha.

BTW, better use 'new-style' classes (that is - for short-, classes that 
inherit at least from 'object' or any other new-style class), ie:

class NewStyle(object):
   # this is a new-style class
   pass

class NewStyleToo(NewStyle):
   # this is a new-style class too
   pass

class OldStyle:
   # this is a deprecated old-style class


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

Yes, this is definitively a nice place !-)



More information about the Python-list mailing list