Overriding __init__() questions

G

grocery_stocker

What's the difference between doing something calling A.__init__(self)
like in the following...

[cdalten@localhost ~]$ python
Python 2.4.3 (#1, Oct 1 2006, 18:00:19)
[GCC 4.1.1 20060928 (Red Hat 4.1.1-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information..... def __init__(self):
.... pass
........ def __init__(self, x):
.... A.__init__(self)
.... self.x = x
.... print x
....Traceback (most recent call last):

versus something like the following....

[cdalten@localhost ~]$ python
Python 2.4.3 (#1, Oct 1 2006, 18:00:19)
[GCC 4.1.1 20060928 (Red Hat 4.1.1-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information..... def __init__(self):
.... pass
........ def __init__(self, x):
.... self.x = x
.... print x
....Traceback (most recent call last):

Just curious because the former seems to be common when using the
python Thread module.
 
T

Terry Reedy

grocery_stocker said:
What's the difference between doing something calling A.__init__(self)
like in the following...

[cdalten@localhost ~]$ python
Python 2.4.3 (#1, Oct 1 2006, 18:00:19)
[GCC 4.1.1 20060928 (Red Hat 4.1.1-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.... def __init__(self):
... pass
...... def __init__(self, x):
... A.__init__(self)
... self.x = x
... print x
...Traceback (most recent call last):

versus something like the following....

[cdalten@localhost ~]$ python
Python 2.4.3 (#1, Oct 1 2006, 18:00:19)
[GCC 4.1.1 20060928 (Red Hat 4.1.1-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.... def __init__(self):
... pass
...... def __init__(self, x):
... self.x = x
... print x

In one you call A.__init__ and the other you don't. If A.__init__ does
something useful, as it usually would, then not calling it would not get
that useful work done. Or you repeat the useful code of A.__init__ in
B.__init__, which is not a good idea, especially when you have to change
that code in two places.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top