Python multiple inheritance questions -



Python multiple inheritance questions -

sorry if question has been asked before, not find reply while searching other questions.

i'm new python , i'm having issues multiple inheritance. suppose have 2 classes, b , c, inherit same class a, defined follows:

class b(a): def foo(): ... homecoming def bar(): ... homecoming class c(a): def foo(): ... homecoming def bar(): ... homecoming

i want define class d, inherits both b , c. d should inherit b's implementation of foo, c's implementation of bar. how go doing this?

resisting temptation "avoid situation in first place", 1 (not elegant) solution wrap methods explicitly:

class a: pass class b( ): def foo( self ): print( 'b.foo') def bar( self ): print( 'b.bar') class c( ): def foo( self ): print( 'c.foo') def bar( self ): print( 'c.bar') class d( b, c ): def foo( self ): homecoming b.foo( self ) def bar( self ): homecoming c.bar( self )

alternatively can create method definitions explicit, without wrapping:

class d( b, c ): foo = b.foo bar = c.bar

python inheritance multiple-inheritance

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -