Skip to content

Instantly share code, notes, and snippets.

@Everfighting
Last active June 21, 2022 09:26
Show Gist options
  • Save Everfighting/7b280f628bad7d38b9679aa2d61bc01b to your computer and use it in GitHub Desktop.
Save Everfighting/7b280f628bad7d38b9679aa2d61bc01b to your computer and use it in GitHub Desktop.
例如,以下的代码是错误的:
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