class Rational(object):

    def __eq__(self, other):
        for attr in ['numerator', 'denominator']:
            v1, v2 = [getattr(obj, attr, _NOTFOUND) for obj in [self, other]]
Comparing two objects