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)
>
>
>> 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 pa
[cut]
>
> Yes, that is the more modern way to do it for new-style classes. In the
> original example, class A does not inherit from object so I used the older
> style.
>
Thanks guys for your answers, it's clear (even if I wouldn't be able
to figure it out by my own).
About old style/new style
Cedric BRINER wrote:
>>>However, is it possible to achieve this without rewrite the whole
>>>__init__ method, but just overriding parts of it?
>>
>>The usual way to do this is to forward to the __init__() method of the
>>superclass for the common part. In your case you are just specializing the
>
> > However, is it possible to achieve this without rewrite the whole
> > __init__ method, but just overriding parts of it?
>
> The usual way to do this is to forward to the __init__() method of the
> superclass for the common part. In your case you are just specializing the
> default arguments
Negroup - wrote:
> I have this class:
>
class A:
>
> ... def __init__(self, blank=False, editable=True, name='foo'):
> ... self.blank = blank
> ... self.editable = editable
> ... self.name = name
> ...
>
a = A()
a.blank, a.editable, a.name
>
>
I have this class:
>>> class A:
... def __init__(self, blank=False, editable=True, name='foo'):
... self.blank = blank
... self.editable = editable
... self.name = name
...
>>> a = A()
>>> a.blank, a.editable, a.name
(False, True, 'foo')
All as expected.
No