Thanks for reading. Preface, I don't mean how to make a print(objectA) make python output something other than the <__main__.A object at 0x00000273BC36A5C0> via the redefining the __str__ attribute.
I will use the following example to try to explain what I'm doing.
class Point: ''' Represents a point in 2D space attributes: x, y ''' def __init__(self, x=0, y=0): allowed_types = {int, float} if type(x) not in allowed_types or type(y) not in allowed_types: raise TypeError('Coordinates must be numbers.') else: self.x = x self.y = y def __str__(self): return f' "the points name" has the points: ({self.x}, {self.y})' __repr__ = __str__ I would like the "the points name" to be replaced with whatever the variable name assigned to a specific object. So if I instantiated pointA=Point(1,0), I would like to be able to print pointA has the points: (1,0)
I can't seem to find anything like this online, just people having issues that are solved by redefining __str__. I tried to solve this issue by adding a .name attribute, but that made this very unwieldy (especially since I want to make other object classes that inherit Point()). I'm not entirely sure if this is possible from what I know about variable and object names in python, but after wrestling with it for a couple of days I'd figured I'd reach out for ideas.
A=B=Point(), and have a point with multiple names. You could doprint(Point()), and have a point that was never assigned to a name at all. This is simply not something that's going to work in Python.