I am trying to implement a very basic Java-like Dimension-Class in Python:
class Dimension(object):
def __init__(self, width, height):
self.__width = width
self.__height = height
@property
def width(self):
return self.__width
@property
def height(self):
return self.__height
d = Dimension(800, 400)
print d.width
print d.height
This works fine: d.width returns an int=800, d.height returns an int=400.
But how do I define, that d should return a tuple=(800,400) instead of
<__main__.Dimension object at 0xXXXXXXXX>
?
Is there an in-built class function similar to __repr__
for it?
How do I define the returned value of a custom class?
Or do I have to implement a new type?
Thank you