ch11-24: clean up by @eumiro & sync with Atlas
This commit is contained in:
14
17-it-generator/tree/step6/tree.py
Normal file
14
17-it-generator/tree/step6/tree.py
Normal file
@@ -0,0 +1,14 @@
|
||||
def tree(cls, level=0):
|
||||
yield cls.__name__, level
|
||||
for sub_cls in cls.__subclasses__():
|
||||
yield from tree(sub_cls, level+1)
|
||||
|
||||
|
||||
def display(cls):
|
||||
for cls_name, level in tree(cls):
|
||||
indent = ' ' * 4 * level
|
||||
print(f'{indent}{cls_name}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
display(BaseException)
|
||||
Reference in New Issue
Block a user