newb __init__ inheritance

Ian Kelly ian.g.kelly at gmail.com
Sun Mar 11 07:52:48 EDT 2012


On Sun, Mar 11, 2012 at 5:40 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> 2. Is the mro function available only on python3?
>
> No, but it is available only on new-style classes.  If you try it on a
> classic class, you'll get an AttributeError.

And by the way, you probably shouldn't call the mro method directly.
That method is provided so that it can be overridden in order to
customize the MRO at class creation.  The proper (and faster) way to
look up the MRO for a class is using the __mro__ attribute, which
stores the result of the mro method when the class is initialized.

http://docs.python.org/library/stdtypes.html?highlight=mro#class.__mro__

Cheers,
Ian



More information about the Python-list mailing list