Overriding __eq__ and comparing two objects
<p>I have two unique Temperature objects that I need to compare to each other, however, since the objects can be equal but have different units, I'm running into trouble comparing them.</p>

<p>For example</p>

<p><code>t1 = Temperature(32.0, 'F')</code></p>

<p><code>t2 = Temperature(0.0, 'C')</code></p>

<p>These two objects are equal, but I can't seem to get the correct implementation of <code>__eq__</code> to compare them</p>

<p>Here's what I have tried</p>

<pre><code>class Temperature():

    def __init__(self, temp = 0.0, unit = 'C'):
        if float(temp) == str(temp):
            raise ValueError('could not convert string to float: ' + "'" + str(temp) + "'")
        else:
            self.t = float(temp)
        if unit.upper() not in 'CF':
            raise UnitError('Unrecognized temperature unit ' + "'" + str(unit) + "'")
        else:
            self.u = unit.upper()

    def __repr__(self):
        return "Temperature({},'{}')".format(self.t, self.u)

    def __str__(self):
        return str(self.t) + '°' + self.u.upper()

    def __eq__(self, other):
        t1 = Temperature(self.t, self.u)
        t2 = Temperature(other.t, other.u)
        other.convert()

        if t1.t == t2.t and t1.u == t2.u:
            return True
        return False

    def convert(self):
        t = Temperature(self.t, self.u)
        if t.u.upper() == 'C':
            t.t *= 1.8
            t.t += 32
            t.u = 'F'
            return t
        else:
            t.t -= 32
            t.t /= 1.8
            t.u = 'C'
            return t
</code></pre>

<p>Notice that I do have a method to convert temperatures from one unit to another. Again, I can't seem to figure out how to compare the two objects, when they are in different units.</p>