A
Axel Straschil
Hello!
I'm working on an HTML/Cgi widget's class where multiple inheritance
well be sometime a great thing.
I solved all my problems for pythons multiple inheritance with this ng,
thaks to all again, but there is one think I still dislike:
class A(object):
def __init__(self, a=None, **__eat):
print "A"
super(A, self).__init__()
class B(object):
def __init__(self, b=None, **__eat):
print "B"
super(B, self).__init__()
class AB(A, B):
def __init__(self, a=None, b=None):
super(AB, self).__init__(a=a, b=b)
ab = AB()
This looks (and I think is) correct, but I realy dislike the **__eat
stuff. As in python everything is virtual, I found no better solution to
do that. In my real world, i've got constucts like:
class A(object)
class B(A)
class AB(A,B)
(not realy so ugly like that ;-), just to say I can work only with super to
call __init__).
My problem: If you make a coding mistake, and the mistake does not give
a runtime error becouse **__eat is a hungry evil beast, it would be very
hard to debug ... think of a wrong written parameter!
So, here is my workaround, please comment this, if someone has a better
solution I would be glad:
class A(object):
def __init__(self, a=None, _do_eat=False, **__eat):
if __eat and not _do_eat: raise "I'm not hungry"
print "A"
super(A, self).__init__()
class B(object):
def __init__(self, b=None, _do_eat=False, **__eat):
if __eat and not _do_eat: raise "I'm not hungry"
print "B"
super(B, self).__init__()
class AB(A, B):
def __init__(self, a=None, b=None):
super(AB, self).__init__(a=a, b=b, _do_eat=True)
ab = AB()
Thanks,
AXEL.
I'm working on an HTML/Cgi widget's class where multiple inheritance
well be sometime a great thing.
I solved all my problems for pythons multiple inheritance with this ng,
thaks to all again, but there is one think I still dislike:
class A(object):
def __init__(self, a=None, **__eat):
print "A"
super(A, self).__init__()
class B(object):
def __init__(self, b=None, **__eat):
print "B"
super(B, self).__init__()
class AB(A, B):
def __init__(self, a=None, b=None):
super(AB, self).__init__(a=a, b=b)
ab = AB()
This looks (and I think is) correct, but I realy dislike the **__eat
stuff. As in python everything is virtual, I found no better solution to
do that. In my real world, i've got constucts like:
class A(object)
class B(A)
class AB(A,B)
(not realy so ugly like that ;-), just to say I can work only with super to
call __init__).
My problem: If you make a coding mistake, and the mistake does not give
a runtime error becouse **__eat is a hungry evil beast, it would be very
hard to debug ... think of a wrong written parameter!
So, here is my workaround, please comment this, if someone has a better
solution I would be glad:
class A(object):
def __init__(self, a=None, _do_eat=False, **__eat):
if __eat and not _do_eat: raise "I'm not hungry"
print "A"
super(A, self).__init__()
class B(object):
def __init__(self, b=None, _do_eat=False, **__eat):
if __eat and not _do_eat: raise "I'm not hungry"
print "B"
super(B, self).__init__()
class AB(A, B):
def __init__(self, a=None, b=None):
super(AB, self).__init__(a=a, b=b, _do_eat=True)
ab = AB()
Thanks,
AXEL.