<s>[INST] Compare object instances for equality by their attributes in Python What is the best way to compare two instances of some object for equality in Python? I'd like to be able to do something like
Example:
doc1 = ErrorDocument(path='/folder',title='Page')
doc2 = ErrorDocument(path='/folder',title='Page')

if doc1 == doc2: # this should be True
    #do something

EDIT:
To further clarify the question. I'd like to compare by attribute values, and to make a more generic solution than 
def __eq__(self, other):
    return self.path == other.path and self.title == other.title

Should the __eq__() method look something like this?
def __eq__(self, other):
    # Is the other instance of the same object
    # Loop through __dict__ and compare values to attributes of other

 [/INST] As usual with Python, it's kiss :
class Test(object):

    def __init__(self, attr1, attr2):
        self.attr1 = attr1
        self.attr2 = attr2

    def __str__(self):
        return str(self.__dict__)

    def __eq__(self, other): 
        return self.__dict__ == other.__dict__

t1 = Test("foo", 42)
t2 = Test("foo", 42)
t3 = Test("bar", 42)

print t1, t2, t3
print t1 == t2
print t2 == t3

It outputs:
{'attr2': 42, 'attr1': 'foo'} {'attr2': 42, 'attr1': 'foo'} {'attr2': 42, 'attr1': 'bar'}
True
False

N.B : be aware that before Python 3.0, you are more likely to use __cmp__ instead of __eq__, working the same way.
 </s>