Re: [Tutor] super constructor usage

2017-03-31 Thread Alan Gauld via Tutor
On 30/03/17 21:08, Alan Gauld via Tutor wrote: > Of course, the __init__ methods are special in any way Should have said *not special* in any way... > But remember that not calling super potentially leaves > some attributes of your superclass uninitialized. By not > calling super you assume full

Re: [Tutor] super constructor usage

2017-03-31 Thread Mats Wichmann
On 03/30/2017 05:39 AM, Rafael Knuth wrote: I am trying to wrap my head around the super constructor. > > Is it possible to embed a super constructor into an if / elif > statement within the child class? > > if message == "string A": return X > elif: return Y > > How should I modify my code

Re: [Tutor] super constructor usage

2017-03-30 Thread Alan Gauld via Tutor
On 30/03/17 12:39, Rafael Knuth wrote: I am trying to wrap my head around the super constructor. > > Is it possible to embed a super constructor into an if / elif > statement within the child class? Of course, the __init__ methods are special in any way the normal coding mechanisms all work.

Re: [Tutor] super constructor usage

2017-03-30 Thread Rafael Knuth
>> > I am trying to wrap my head around the super constructor. Is it possible to embed a super constructor into an if / elif statement within the child class? if message == "string A": return X elif: return Y How should I modify my code below? (I couldn't solve that by myself) class A: def

Re: [Tutor] super constructor usage

2017-03-30 Thread Mats Wichmann
On 03/29/2017 08:33 AM, Rafael Knuth wrote: > class A: > def __init__(self, message): > self.message = message > print(message) > > I then modified the child class B like this: > > class B(A): > def __init__(self, message): > print("This is the message from your p

Re: [Tutor] super constructor usage

2017-03-30 Thread Mats Wichmann
On 03/29/2017 04:02 PM, Mats Wichmann wrote: > On 03/29/2017 08:33 AM, Rafael Knuth wrote: > >> class A: >> def __init__(self, message): >> self.message = message >> print(message) >> >> I then modified the child class B like this: >> >> class B(A): >> def __init__(self,

Re: [Tutor] super constructor usage

2017-03-29 Thread Steven D'Aprano
On Wed, Mar 29, 2017 at 10:32:52PM +0100, Alan Gauld via Tutor wrote: > On 29/03/17 15:33, Rafael Knuth wrote: > > I am trying to wrap my head around the super constructor. > > This is one of these cases where it matters whether you > are using Python v2 or v3. Use of super in v3 is much > easier

Re: [Tutor] super constructor usage

2017-03-29 Thread Steven D'Aprano
On Wed, Mar 29, 2017 at 04:33:20PM +0200, Rafael Knuth wrote: > I am trying to wrap my head around the super constructor. Simple example: > > class A: > def __init__(self): > print("world") > > class B(A): > def __init__(self): > print("hello") > super(B, self).__i

Re: [Tutor] super constructor usage

2017-03-29 Thread Alan Gauld via Tutor
On 29/03/17 15:33, Rafael Knuth wrote: > I am trying to wrap my head around the super constructor. This is one of these cases where it matters whether you are using Python v2 or v3. Use of super in v3 is much easier. It looks from your examples like you are using v2 but it would be good to confir

[Tutor] super constructor usage

2017-03-29 Thread Rafael Knuth
I am trying to wrap my head around the super constructor. Simple example: class A: def __init__(self): print("world") class B(A): def __init__(self): print("hello") super(B, self).__init__() B() Then I changed the parent class A like this, as I wanted to test how