Closed LondonClass closed 2 months ago
I don't think this has anything to do with the sprite class, it's just your use of __getattr__
.
class Test:
def __init__(self, val):
self.val = val
def __getattr__(self, name):
return self.x
a = Test(2)
print(a.x)
Traceback (most recent call last):
File "C:\Users\charl\Desktop\test7.py", line 10, in <module>
print(a.x)
File "C:\Users\charl\Desktop\test7.py", line 6, in __getattr__
return self.x
File "C:\Users\charl\Desktop\test7.py", line 6, in __getattr__
return self.x
File "C:\Users\charl\Desktop\test7.py", line 6, in __getattr__
return self.x
[Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceeded
Many ways can lead to infinite recursion.
1.Just print self.
2.Using an undefined variable
If I want to implement this function:
Method 1:
Method 2:
Method 3: