__bases__ attribute on classes not displayed by dir() command

eryk sun eryksun at gmail.com
Thu Feb 4 03:56:46 EST 2016


On Thu, Feb 4, 2016 at 2:03 AM, ast <nomail at invalid.com> wrote:
> but if I am using dir to display all Carre's attributes and methods,
> __bases__ is not on the list. Why ?

The __bases__ property is defined by the metaclass, "type". dir() of a
class doesn't show attributes from the metaclass [1].

    Because dir() is supplied primarily as a convenience for use at an
    interactive prompt, it tries to supply an interesting set of names
    more than it tries to supply a rigorously or consistently defined set
    of names, and its detailed behavior may change across releases.
    For example, metaclass attributes are not in the result list when
    the argument is a class.

To see the metaclass attributes use dir(type(Carre)).

[1]: https://docs.python.org/3/library/functions.html#dir


More information about the Python-list mailing list