Last active
June 21, 2022 09:26
-
-
Save Everfighting/7b280f628bad7d38b9679aa2d61bc01b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
例如,以下的代码是错误的: | |
class Student(object): | |
# 方法名称和实例变量均为birth: | |
@property | |
def birth(self): | |
return self.birth | |
这是因为调用s.birth时,首先转换为方法调用,在执行return self.birth时,又视为访问self的属性, | |
于是又转换为方法调用,造成无限递归,最终导致栈溢出报错RecursionError。 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment