0

I have the following three classes:

class foo(object):
    pass
class bar(foo):
    pass
class baz(bar):
    pass

I want a method that does something like this:

>>> class_stack(baz)
baz > bar > foo

1 Answer 1

5

Perhaps you are looking for the MRO (method resolution order):

In [32]: baz.mro()
Out[32]: [__main__.baz, __main__.bar, __main__.foo, object]

In [33]: [cls.__name__ for cls in baz.mro()]
Out[33]: ['baz', 'bar', 'foo', 'object']

In [34]: ' > '.join([cls.__name__ for cls in baz.mro()])
Out[34]: 'baz > bar > foo > object'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.