Default argument values are evaluated at function define-time, but self
is an argument only available at function call time. Thus arguments in the argument list cannot refer each other.
It's a common pattern to default an argument to None
and add a test for that in code:
def p(self, b=None):
if b is None:
b = self.a
print b
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…