I have the following (example) code:
class _1DCoord():
def __init__(self, i):
self.i = i
def pixels(self):
return self.i
def tiles(self):
return self.i/TILE_WIDTH
What I want to do is this:
>>> xcoord = _1DCoord(42)
>>> print xcoord
42
But instead I see this:
>>> xcoord = _1DCoord(42)
>>> print xcoord
<_1DCoord instance at 0x1e78b00>
I tried using __repr__ as follows:
def __repr__(self):
return self.i
But __repr__ can only return a string.
Is there any way to do what I’m trying to do, or should I just give up and use pixels()?
1 Answer