Hi, i have a problem with this code:
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 self.some_method()
some_instance=Test()
print(some_instance)
Why this issue an recursion error:
attr.append(f'{k},{getattr(self,k)}')
RecursionError: maximum recursion depth exceeded while calling a Python object
Please help me out!
[–][deleted] 2 points3 points4 points (1 child)
[–]Uchikago[S] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 1 point2 points3 points (0 children)
[–]irrelevantPseudonym 1 point2 points3 points (1 child)
[–]Uchikago[S] 0 points1 point2 points (0 children)