[code]class A(object):
def __init__(self, a=None, b=None, *args, **kwargs):
super().__init__(*args, **kwargs)
print('Init {} with arguments {}'.format(self.__class__.__name__, (a, b)))
print ('A')
class B(object):
def __init__(self, q=None, *args, **kwargs):
super().__init__(*args, **kwargs)
print('Init {} with arguments {}'.format(self.__class__.__name__, (q)))
print ('B')
class C(A, B):
def __init__(self):
super().__init__()
print ('C')
[/code]
What I got is
[code]Init C with arguments (None, None)
A
C[/code]
So the question is why class B 's fun __init__() is not be called.
How can I correct the code??
Multiple inheritance in python3 with micropython
Re: Multiple inheritance in python3 with micropython
Is it a bug that micropython can't use super()?
when I use micropython I get
But if I run this on my pc I get
why this happen??
Code: Select all
class A:
def __init__(self):
print("A.__init__")
class B(A):
def __init__(self):
print("B.__init__")
super().__init__()
class C(A):
def __init__(self):
print("C.__init__")
super().__init__()
class D(B,C):
def __init__(self):
print("D.__init__")
super().__init__()
D()
Code: Select all
D.__init__
B.__init__
A.__init__
MicroPython v1.5.1-58-gb4eccfd on 2015-12-03; PYBv1.0 with STM32F405RG
Type "help()" for more information.
Code: Select all
D.__init__
B.__init__
C.__init__
A.__init__
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Multiple inheritance in python3 with micropython
I think you've hit a bug in Micropython. I'll raise an issue on Github.
Incidentally when posting code to the forum it's worth using the Code button: this preserves indentation making the code easier to read. It also makes it easier to cut and paste when we want to try it
Incidentally when posting code to the forum it's worth using the Code button: this preserves indentation making the code easier to read. It also makes it easier to cut and paste when we want to try it
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.