I am writing a code which tries to dig deep into the input object and find out a value lying inside that object. Here is a sample code:
def GetThatValue(inObj):
if inObj:
level1 = inObj.GetBelowObject()
if level1:
level2 = level1.GetBelowObject()
if level2:
level3 = level2.GetBelowObject()
if level3:
return level3.GetBelowObject()
return None
There are many situations where I end up with these "slanted if conditions". How can I avoid this? This looks dirty and also it is kind of defensive programming.