In JavaScript (and Node.js and TS), when we have an object A which has an attribute B, which has an attribute C, which has an attribute D and so on, we may use it like that:
const x = A?.B?.C?.D
Is there something similar in Python?
I want x to be None if any of A, B, C, or D is None. Actually, I need x = A.B.C.D or DEFAULT_VALUE
What I do today is very verbose:
x = None
if A is not None and A.B is not None and A.B.C is not None:
x = A.B.C.D
Is there a one-line solution in Python?
I prefer an approach like this, but it is still very verbose and I repeat myself. Looking for DRY.
x = A and A.B and A.B.C and A.B.C.D or DEFAULT_VALUE