ch17: update from book draft
This commit is contained in:
1 parent
70650841b3
commit
aa868e8f75
35 files changed
+788
-31
No files matched your search
@@ -0,0 +1,7 @@
|
||||
def tree(cls):
|
||||
yield cls.__name__
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
for cls_name in tree(BaseException):
|
||||
print(cls_name)
|
||||
@@ -0,0 +1,10 @@
|
||||
def tree(cls):
|
||||
yield cls.__name__, 0
|
||||
for sub_cls in cls.__subclasses__():
|
||||
yield sub_cls.__name__, 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
for cls_name, level in tree(BaseException):
|
||||
indent = ' ' * 4 * level
|
||||
print(f'{indent}{cls_name}')
|
||||
@@ -0,0 +1,12 @@
|
||||
def tree(cls):
|
||||
yield cls.__name__, 0
|
||||
for sub_cls in cls.__subclasses__():
|
||||
yield sub_cls.__name__, 1
|
||||
for sub_sub_cls in sub_cls.__subclasses__():
|
||||
yield sub_sub_cls.__name__, 2
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
for cls_name, level in tree(BaseException):
|
||||
indent = ' ' * 4 * level
|
||||
print(f'{indent}{cls_name}')
|
||||
@@ -0,0 +1,10 @@
|
||||
def tree(cls, level=0):
|
||||
yield cls.__name__, level
|
||||
for sub_cls in cls.__subclasses__():
|
||||
yield from tree(sub_cls, level + 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
for cls_name, level in tree(BaseException):
|
||||
indent = ' ' * 4 * level
|
||||
print(f'{indent}{cls_name}')
|
||||
Reference in new issue
Block a user