Getting not derived members of a class
Brian Beck
exogen at gmail.com
Mon Aug 1 13:35:11 EDT 2005
George Sakkis wrote:
>>>>z = Z()
>>>>z.__class__.__mro__
>
> (<class '__main__.Z'>, <class '__main__.Y1'>, <class '__main__.Y2'>,
> <class '__main__.X'>, <type 'object'>)
>
> Old style classes don't have __mro__, so you have to write it yourself;
> in any case, writing old style classes in new code is discouraged.
Notice also that George's __mro__ solution returns the bases in reverse
order than what you requested (in your example, you said B should come
last). So use list(reversed(z.__class__.__mro__)) or
z.__class__.__mro__[::-1]
--
Brian Beck
Adventurer of the First Order
More information about the Python-list
mailing list