This is my directory's structure:
This is the declaration.py
code:
class Declaration:
def __init__(self, prop, prop_value):
self.prop = prop
self.prop_value = prop_value
def __repr__(self):
str = f'{self.prop}: {self.prop_value}'
return str
This is the main.py
code:
from structure.declaration import Declaration
dec = Declaration('color', 'red')
print(dec)
When I run the main.py
file, I get:
<structure.declaration.Declaration object at 0x03992748>
Instead of expected output:
color: red
What wrong with my code?
question from:
https://stackoverflow.com/questions/65879987/cannot-print-object-repr-using-repr-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…