Equality operator in Python
<p>I have a class Foo, with an equality operator defined as follows:</p>

<pre><code>class Foo(object):
    def __init__(self, item_id):
        self.item_id = item_id

    def __eq__(self, other):
        if isinstance(other, self.__class__):
            print 'DEBUG: self:',self.__dict__ 
            print 'DEBUG: other:',other.__dict__ 
            return self.__dict__ == other.__dict__
        else:
            print 'DEBUG: ATTEMPT TO COMPARE DIFFERENT CLASSES:',self.__class__,'compared to:', other.__class__
            return False
</code></pre>

<p>I have a collection (list) of Foo objects, and I have the following naive search algo:</p>

<pre><code>def find_item_in_foo_list(foo_list, item):
    print 'DEBUG: Item being sought:', item
    num_items = len(foo_list)
    for pos in range(num_items):
        temp = foo_list[pos]
        if temp == item:
            print 'DEBUG: item FOUND:', temp
            return pos

    print 'ERROR: ITEM NOT FOUND!', item
    return None
</code></pre>

<p>When I created a list of Foo objects and searched for an item in the list, I expected to see the equality operator debug statements </p>

<pre><code>foo1 = Foo(1)
foo2 = Foo(2)
foo3 = Foo(3)
foo4 = Foo(4)

foo_list = [foo1,foo2,foo3,foo4]
item = Foo(1)

pos = find_item_in_foo_list(foo_list, item)
</code></pre>

<p>Using the code snippet above, The debug statement from the equality operator are printed to console (which dosen't help - because I am unable to reproduce the problem with my script).</p>

<p>In my script however, its only the debug statements from my <code>find_item_in_foo_list()</code> function that are printed to the console. Sometimes an item is not found - but I can't work out why it is not being found, since I would have previously placed the item in the list earlier on in the code. The problem is being caused by the fact that the debug statements are not being printed by my equality operator - so I cant tell what's going wrong.</p>

<p>Can anyone explain what could be preventing the debug statements in the equality operator from printing?</p>
