模块“sys”没有属性“last_traceback”

问题描述 投票:0回答:1

有点困惑这是否是标准属性。文档字符串说它确实存在。

In [1]: import sys

In [2]: sys.last_traceback
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----> 1 sys.last_traceback

AttributeError: module 'sys' has no attribute 'last_traceback'
python traceback
1个回答
0
投票

原来文档解释了它——它是唯一可用的

  • 发生错误后
  • 在互动会议中

见下文

?sys

Out[1]: Type:        module
String form: <module 'sys' (built-in)>
Docstring:
This module provides access to some objects used or maintained by the
interpreter and to functions that interact strongly with the interpreter.

Dynamic objects:

argv -- command line arguments; argv[0] is the script pathname if known
path -- module search path; path[0] is the script directory, else ''
modules -- dictionary of loaded modules

displayhook -- called to show results in an interactive session
excepthook -- called to handle any uncaught exception other than SystemExit
  To customize printing in an interactive session or to install a custom
  top-level exception handler, assign other functions to replace these.

stdin -- standard input file object; used by input()
stdout -- standard output file object; used by print()
stderr -- standard error object; used for error messages
  By assigning other file objects (or objects that behave like files)
  to these, it is possible to redirect all of the interpreter's I/O.

last_type -- type of last uncaught exception
last_value -- value of last uncaught exception
last_traceback -- traceback of last uncaught exception
  These three are only available in an interactive session after a
  traceback has been printed.
© www.soinside.com 2019 - 2024. All rights reserved.