Python 是否仅打印上次回溯?

Python 是否仅打印上次回溯?,python,python-3.x,traceback,Python,Python 3.x,Traceback,考虑以下代码和回溯: >>> try: ... raise KeyboardInterrupt ... except KeyboardInterrupt: ... raise Exception ... Traceback (most recent call last): File "<stdin>", line 2, in <module> KeyboardInterrupt During handling of the above exc

考虑以下代码和回溯:

>>> try:
...  raise KeyboardInterrupt
... except KeyboardInterrupt:
...  raise Exception
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
Exception
>>> 

对我来说这是个完美的问题

通过显式地将异常
从None提升到None,可以抑制异常上下文,这是回溯的第一部分:

>>> try:
        raise KeyboardInterrupt
    except:
        raise Exception from None

Traceback (most recent call last):
  File "<pyshell#4>", line 4, in <module>
    raise Exception from None
Exception
“get”是指获取异常对象,还是指不打印上下文信息?如果您是指第二种情况,您想要某种全局解释器设置,还是应用于特定异常的设置?
>>> try:
        raise KeyboardInterrupt
    except:
        raise Exception from None

Traceback (most recent call last):
  File "<pyshell#4>", line 4, in <module>
    raise Exception from None
Exception
try:
    try:
        raise Exception('inner')
    except:
        raise Exception('outer') from None
except Exception as e:
    print(e.__context__) # inner