newb __init__ inheritance

Peter Otten __peter__ at web.de
Sun Mar 11 13:12:25 CET 2012


Ian Kelly wrote:

> 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__

Is it a good idea to use mro() or __mro__ at all? Are there common use cases 
that cannot be addressed with super()?




More information about the Python-list mailing list