I am working with threejs
and I would like to override some magic methods like __repr__
to make my debugging life a little easier.
For example, I have a Python v
variable containing a THREE.Vector3
object. I have tried the following, hoping to get a more friendly representation, but it didn’t work:
print(v)
# -> <Vector3 proxyobject>
def new_repr(self):
print(f'<{self.__class__.__name__}({self.x}, {self.y}, {self.z})>')
v.__repr__ = new_repr
v.__class__.__repr__ = new_repr
print(v)
# -> <Vector3 proxyobject>
repr(v)
# -> '<Vector3 proxyobject>'
new_repr(v)
# -> <Vector3(750, 1000, 600)>
It doesn’t work because I am trying the wrong way or because it is impossible?