I want to display a list of all accessible attribute of an instance, so i try this
class Test:
a=2 #initializing some attribute
b=1 #initializing some attribute
def some_method(self):
attr=[]
for k in [i for i in dir(self) if not i.startswith('__')]:
attr.append(f'{k}={getattr(self,k)}') #to collect all attributes and their values pair
return attr
def __repr__(self): #because i want to overload print behavior
return str(self.some_method())
some_instance=Test()
print(some_instance)
And it returned an error:
RecursionError: maximum recursion depth exceeded while calling a Python object
Why did that happen ? And how to fix that ?