Extending classes __init__behavior for newbies

rantingrick rantingrick at gmail.com
Sun Feb 13 18:12:00 EST 2011


On Feb 13, 5:01 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> On Mon, 14 Feb 2011 08:27:10 +1000, James Mills wrote:

> > What's the difference between calling the base class's constructor
> > directly and using the super type ?
>
> If you have *only* single inheritance, then there is no practical
> difference and no harm in using super().

False! There IS harm in using super when super not needed. The
difference is readability! And don't downplay that aspect. You
yourself have said this in the past. It seems *some* of us have very
short memories.

> If you have multiple inheritance, then you *must* use super(), otherwise
> your method will not correctly call all the superclasses that it needs to.

True! You must you super in this case or in any case where you DO NOT
know the identifier of the base class. However the point is: NEVER USE
SUPER UNLESS YOU ABSOLUTELY HAVE NO OTHER OPTION!




More information about the Python-list mailing list