473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

multiple inharitance super() question

Hi,

Before 2.2 I could initialize multiple super classes like this:
class B(A,AA):
def __init__(self, args):
A.__init__(self,args)
AA.__init__(self,args)

Tutorials say that since python 2.2 superclasses should be initialized
with the super() construct.

class A(object):
def __init__(self, args):
...

class B(A):
def __init__(self, args):
super(B, self).__init__(args)
BUT what happens if B extends from A and AA like:

class A(object):
def __init__(self, args):
...

class AA(object):
def __init__(self, args):
...

class B(A,AA):
def __init__(self, args):
super(B, self).__init__(args)
How can I tell that B.__init__() should initialize A and AA?
Or is the new super() so clever to call A.__init__() and AA.__init__()
internally?

thanks,
Alex Greif
________________________________________
http://www.fotobuch-xxl.de/
Nov 22 '05 #1
1 1593
Alex Greif wrote:
BUT what happens if B extends from A and AA like:

class A(object):
def*__init__(self,*args):
...

class AA(object):
def*__init__(self,*args):
...

class B(A,AA):
def*__init__(self,*args):
super(B,*self).__init__(args)
How can I tell that B.__init__() should initialize A and AA?
Or is the new super() so clever to call A.__init__() and AA.__init__()
internally?


Yes but only if you put a super() call into A/AA.__init__().

class A(object):
def __init__(self, args):
print "init A"
super(A, self).__init__(args)

class AA(object):
def __init__(self, args):
print "init AA"
super(AA, self).__init__(args)
class B(A, AA):
def __init__(self, args):
print "init B"
super(B, self).__init__(args)

if __name__ == "__main__":
B(42)

The most significant constraint of that layout is that all __init__()
methods need compatible signatures.
Of course explicit invocation of baseclass initializers will continue to
work...

Peter

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Eric S. Johansson | last post by:
I have an application where I need a very simple database, effectively a very large dictionary. The very large dictionary must be accessed from multiple processes simultaneously. I need to be...
5
by: Jeffrey Barish | last post by:
I have a small program that I would like to run on multiple platforms (at least linux and windows). My program calls helper programs that are different depending on the platform. I think I...
14
by: Axel Straschil | last post by:
Hello! Im working with new (object) classes and normaly call init of ther motherclass with callin super(...), workes fine. No, I've got a case with multiple inherance and want to ask if this...
5
by: newseater | last post by:
i don't know how to call methods of super classes when using multiple inheritance. I've looked on the net but with no result :( class a(object): def foo(self): print "a" class b(object):...
20
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
8
by: Michael J. Fromberger | last post by:
Consider the following class hierarchy in Python: class A (object): def __init__(self): print "cons A" class B (object): def __init__(self): print "cons B"
4
by: HLCruz via AccessMonster.com | last post by:
I am working with a database that has client information separated in to 4 related tables - tFolder, tAddress, tEmail, tPhone number. In addition there are related tables tGifts and tCalls. The...
4
by: Enrico | last post by:
Hi there, I have the following situation (I tryed to minimize the code to concentrate on the issue): def __getattr__(self, name): print 'A.__getattr__' if name == 'a': return 1 raise...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.