'Change the object preview into one of its own attributes
How to change object printing preview into desirable name ?
class Person:
def __init___(self):
self.name = name
self.age = age
man1 = Person("Jhon",32)
print(man1)
>>> <__main__.Person object at 0x7f9780554b80>
I need to change the preview of object into specifice attribute .(e.g: obj.name , in this example i want the preview will be "Jhon_Person_obj" instead the adress of it)
This code describe the printing reasult i need.
print(Jhon_Person_obj)
print(Jhon_Person_obj.age)
>>> <__main__.Personobject at 0x7f9780554bb0>
>>> 32
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
