I was looking at the builtin object methods in the Python documentation, and I was interested in the documentation for object.__repr__(self)
. Here\'s what it sa
It should be a Python expression that, when eval'd, creates an object with the exact same properties as this one. For example, if you have a Fraction
class that contains two integers, a numerator and denominator, your __repr__()
method would look like this:
# in the definition of Fraction class
def __repr__(self):
return "Fraction(%d, %d)" % (self.numerator, self.denominator)
Assuming that the constructor takes those two values.