打印Python异常错误层次结构

打印Python异常错误层次结构,第1张

打印Python异常/错误层次结构

检查模块可能会有所帮助,特别是getclasstree()函数:

将给定的类列表排列为嵌套列表的层次结构。在出现嵌套列表的地方,它包含派生自该类的类,这些类的条目紧接在列表之前。

inspect.getclasstree(inspect.getmro(Exception))

或者,您可以递归遍历

__subclasses__()
继承树,如下所示:

def classtree(cls, indent=0):    print '.' * indent, cls.__name__    for subcls in cls.__subclasses__():        classtree(subcls, indent + 3)classtree(baseException)

印刷品:

 baseException... Exception...... StandardError......... TypeError......... importError............ ZipimportError......... EnvironmentError............ IOError............... ItimerError............ OSError......... EOFError......... RuntimeError............ NotImplementedError......... NameError............ UnboundLocalError......... AttributeError......... SyntaxError............ IndentationError............... TabError......... LookupError............ IndexError............ KeyError............ CodecRegistryError......... ValueError............ UnipreError............... UnipreEnpreError............... UnipreDepreError............... UnipreTranslateError......... AssertionError......... ArithmeticError............ FloatingPointError............ OverflowError............ ZeroDivisionError......... SystemError............ CodecRegistryError......... ReferenceError......... MemoryError......... BufferError...... StopIteration...... Warning......... UserWarning......... DeprecationWarning......... PendingDeprecationWarning......... SyntaxWarning......... RuntimeWarning......... FutureWarning......... importWarning......... UnipreWarning......... BytesWarning...... _OptionError... GeneratorExit... SystemExit... KeyboardInterrupt


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5654725.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存