OOP in python

Alex Martelli aleax at aleax.it
Wed Mar 12 13:00:16 EST 2003


Bob Roberts wrote:

> What exactly do you inherit from another class in python?

You inherit everything that you don't override.

> With no
> type checking in python, the type doesn't matter, 

Type-checking is more often than not a bad idea, but you can do it
(by isinstance and issubclass).  Python does it in one case only --
checking what except clause is applicable, if any, in a try/except
(the first one that catches the type of the exception raised from
the try clause *or any superclass thereof*).

> and the __init__()
> function of the parent doesn't seem to be called 

It's called if it's not overridden.

> (unless you
> explicitly call it yourself).  

If you override some attribute from a parent and still want to
make use of that attribute (be it a method or not) you have to
do it explicitly -- no difference between __init__ and others.


> Does it inherit anything more than just
> the member functions?

Sure, ALL parent class attributes are inherited unless you
override them -- it makes no difference at all whether they're
functions or objects of ANY other type whatsoever.


Alex






More information about the Python-list mailing list