In [1]: class Spam:
...: @property
...: def eggs(self):
...: print("SPAM SPAM SPAM")
...: return "eggs"
...:
In [2]: spam = Spam()
In [3]: _tmp = spam
In [4]: if _tmp is not None:
...: _tmp = _tmp.eggs
...: if _tmp is not None:
...: _tmp = _tmp.bacon
...: food = _tmp
...: del _tmp
...: food
...:
SPAM SPAM SPAM
---------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-9a2f963239f8> in <module>()
2 _tmp = _tmp.eggs
3 if _tmp is not None:
----> 4 _tmp = _tmp.bacon
5 food = _tmp
6 del _tmp
AttributeError: 'str' object has no attribute 'bacon'
In [5]: if spam is not None and spam.eggs is not None:
...: food = spam.eggs.bacon
...:
SPAM SPAM SPAM
SPAM SPAM SPAM
---------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-a24834cdb92b> in <module>()
1 if spam is not None and spam.eggs is not None:
----> 2 food = spam.eggs.bacon
3
AttributeError: 'str' object has no attribute 'bacon'