When you do this:
class C(A): def c(self, num=self.data): print self.data
you are doing something like:
>>> def d(num, data=num): ... print(num, data) ... Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'num' is not defined
And as you can see, the python compiler does not know what the second num .
But nothing prevents you from doing something like:
class C(A): def c(self, num=None): print num or self.data
or with an explicit None check:
class C(A): def c(self, num=None): if num is None: num = self.data print num
source share