[英]What is the type of traceback objects in Python?
import sys
try:
raise Exception('foobar')
except:
info = sys.exc_info()
print(type(e[2])) # <class 'traceback'>
help(traceback) # NameError: name 'traceback' is not defined
What exactly is the type of the traceback objects that Python uses for exception reporting? Python用于异常报告的回溯对象的类型究竟是什么?
The docs on sys.exc_info mention the Reference Manual, but while I've found plenty of information on how to manipulate traceback instances, I want to be able to access the type (class) itself. sys.exc_info上的文档提到了参考手册,但是虽然我发现了很多关于如何操作回溯实例的信息,但我希望能够访问类型(类)本身。
traceback
object is an instance of TracebackType
present under types module. traceback
对象是类型模块下存在的TracebackType
的实例。
types.TracebackType
The type of
traceback
objects such as found insys.exc_info()[2]
.traceback
对象的类型,例如sys.exc_info()[2]
。
>>> from types import TracebackType
>>> isinstance(info[2], TracebackType)
True
>>> TracebackType
<class 'traceback'>
As pointed out by @user2357112 the name TracebackType
is basically an alias to the internal traceback
type and is set by raising an exception in types module. 正如@ user2357112所指出的,
TracebackType
这个名称基本上是内部traceback
类型的别名,它是通过在types模块中引发异常来设置的 。 The actual traceback
type can be found in CPython code. 实际的
traceback
类型可以在CPython代码中找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.