-
-
Save BiTree/79d9a455b63d3b03a74693b2bb010e82 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 Biz(object): | |
def __init__(self, val_a: str, val_b: str, val_c: str, val_d: str) -> None: | |
self._val_a = val_a | |
self._val_b = val_b | |
self._val_c = val_c | |
# 还没有初始化_val_d,但是make_new_val引用了这个变量 | |
self._new_val = self.make_new_val() | |
# 调用了make_new_val后才初始化了_val_d | |
self._val_d = val_d | |
def make_new_val(self) -> str: | |
return self._val_a + self._val_b + self._val_c + self._val_d | |
if __name__ == '__main__': | |
Biz("foo", "bar", "foo1", "bar1").make_new_val() | |
# 执行时程序报错AttributeError: 'Biz' object has no attribute '_val_d' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment