473,379 Members | 1,174 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,379 software developers and data experts.

Class __init__ behaviour

If I insert an __init__ method in my own class definition, it is incumbent
upon me to call the __init__ of any declared ancester to my new class object
because my __init__ will override that of any ancester I declare in the
header. If I fail to call the ancesters __init__, then it won't happen.
The ancester object won't be initialized.

But

If I *don't* insert my own __init__ in my new class, then any declared
ancester __init__ will automatically run because I haven't overridden the
ancesters __init__ method with my own.

Did I get that straight?
Thomas Bartkus
Apr 20 '06 #1
2 1565
Thomas Bartkus schrieb:
If I insert an __init__ method in my own class definition, it is incumbent
upon me to call the __init__ of any declared ancester to my new class object
because my __init__ will override that of any ancester I declare in the
header. If I fail to call the ancesters __init__, then it won't happen.
The ancester object won't be initialized. Yes.

But

If I *don't* insert my own __init__ in my new class, then any declared
ancester __init__ will automatically run because I haven't overridden the
ancesters __init__ method with my own.


No. Only the __init__ of the leftmost ancestor is called. Of course if
that uses the super(..)-method the other constructors get called.

Diez
Apr 20 '06 #2
In article <1L********************@telcove.net>,
"Thomas Bartkus" <th***********@comcast.net> wrote:
If I insert an __init__ method in my own class definition, it is incumbent
upon me to call the __init__ of any declared ancester to my new class object
because my __init__ will override that of any ancester I declare in the
header. If I fail to call the ancesters __init__, then it won't happen.
The ancester object won't be initialized.

But

If I *don't* insert my own __init__ in my new class, then any declared
ancester __init__ will automatically run because I haven't overridden the
ancesters __init__ method with my own.

Did I get that straight?
Thomas Bartkus

Sounds right to me. That's how I use it.

-- Lou Pecora (my views are my own) REMOVE THIS to email me.
Apr 20 '06 #3

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

Similar topics

1
by: Andrew James | last post by:
All, I'm having some trouble with understanding python's importing behaviour in my application. I'm using psyco to optimise part of my code, but I'm not sure whether it inherits throughout the...
6
by: Brian Jones | last post by:
I'm sure the solution may be obvious, but this problem is driving me mad. The following is my code: class a(object): mastervar = def __init__(self): print 'called a'
5
by: Stewart Midwinter | last post by:
I've got an app that creates an object in its main class (it also creates a GUI). My problem is that I need to pass this object, a list, to a dialog that is implemented as a second class. I want...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
2
by: Brian van den Broek | last post by:
Hi all, I've the following code snippet that puzzles me: class Base(object): __v, u = "Base v", "Base u" def __init__(self): print self.__v, self.u class Derived(Base):
7
by: Steven D'Aprano | last post by:
I'm having problems with sub-classes of built-in types. Here is a contrived example of my subclass. It isn't supposed to be practical, useful code, but it illustrates my problem. class...
2
by: Tim Arnold | last post by:
Hi, I'm writing a command-line interface using optparse. The cli takes several options with a single action and several parameters to be used in the resulting worker classes. I've been passing...
2
by: Jan =?UTF-8?B?U2Now6RmZXI=?= | last post by:
Hi all, can anyone explain the behaviour of the following code sniplet: ---schnipp <--- class Base(object): def __init__( self, lst= ): self.varlist = lst def addVar( self, var ):
44
by: Steven D'Aprano | last post by:
I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.