Skip to content

Instantly share code, notes, and snippets.

@BiTree

BiTree/fn.py Secret

Created November 2, 2021 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BiTree/79d9a455b63d3b03a74693b2bb010e82 to your computer and use it in GitHub Desktop.
Save BiTree/79d9a455b63d3b03a74693b2bb010e82 to your computer and use it in GitHub Desktop.
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