[Tutor] Basic class inheritance
Kent Johnson
kent37 at tds.net
Thu Jul 28 20:01:11 CEST 2005
Alan G wrote:
>>> Now I want that another class, call it B, inherits all
>>> behaviours/attributes except for the attribute blank, that now I want
>>> to be False.
>
>
>> class B(A):
>> def __init__(self, blank=True, editable=True, name='foo'):
>> A.__init__(self, blank, editable, name)
>
>
> except that instead of passimng blank to A.__init__ you should pass False.
> That way blank will always be False as required! ie:
>
> A.__init__(self, False, editable, name)
It's not really clear what the OP wants - whether blank should always be False, or have a default value of False. Actually the example shows blank having a default value of True for B's which makes more sense than the text since the default value of blank for A's is False.
Anyway, if you want to change the default value do it the way I showed originally (above); if you want blank to always be False (or True) you should remove the parameter from the definition of B.__init__() like this:
class B(A):
def __init__(self, editable=True, name='foo'):
A.__init__(self, True, editable, name)
Kent
More information about the Tutor
mailing list