python - 如何缩写 Jupyter Notebook 中的回溯?

标签 python jupyter-notebook traceback

我使用 Jupyter Notebook 记录了 XML-API,因此文档和规范不会脱节。

这很好用。

由于 API 还必须处理无效输入,Jupyter Notebook 会正确显示回溯。

回溯非常冗长 - 我想缩写/缩短它 - 理想情况下,只应显示最后一行。

请求

server.get_licenses("not-existing-id")

Jupyter Notebook 中的当前打印输出

---------------------------------------------------------------------------
Fault                                     Traceback (most recent call last)
<ipython-input-5-366cceb6869e> in <module>
----> 1 server.get_licenses("not-existing-id")

/usr/lib/python3.9/xmlrpc/client.py in __call__(self, *args)
   1114         return _Method(self.__send, "%s.%s" % (self.__name, name))
   1115     def __call__(self, *args):
-> 1116         return self.__send(self.__name, args)
   1117 
   1118 ##

/usr/lib/python3.9/xmlrpc/client.py in __request(self, methodname, params)
   1456                         allow_none=self.__allow_none).encode(self.__encoding, 'xmlcharrefreplace')
   1457 
-> 1458         response = self.__transport.request(
   1459             self.__host,
   1460             self.__handler,

/usr/lib/python3.9/xmlrpc/client.py in request(self, host, handler, request_body, verbose)
   1158         for i in (0, 1):
   1159             try:
-> 1160                 return self.single_request(host, handler, request_body, verbose)
   1161             except http.client.RemoteDisconnected:
   1162                 if i:

/usr/lib/python3.9/xmlrpc/client.py in single_request(self, host, handler, request_body, verbose)
   1174             if resp.status == 200:
   1175                 self.verbose = verbose
-> 1176                 return self.parse_response(resp)
   1177 
   1178         except Fault:

/usr/lib/python3.9/xmlrpc/client.py in parse_response(self, response)
   1346         p.close()
   1347 
-> 1348         return u.close()
   1349 
   1350 ##

/usr/lib/python3.9/xmlrpc/client.py in close(self)
    660             raise ResponseError()
    661         if self._type == "fault":
--> 662             raise Fault(**self._stack[0])
    663         return tuple(self._stack)
    664 

Fault: <Fault 1: 'company id is not valid'>

我的愿望输出

Fault: <Fault 1: 'company id is not valid'>

最佳答案

事实证明,它内置于 iPython 中,因此您无需安装或更新任何内容。

只需在笔记本顶部放置一个单元格并运行 %xmode Minimal 作为唯一输入。您还可以使用 %xmode? 查看文档,或者使用 %quickref 查看许多其他“神奇方法”文档。

关于python - 如何缩写 Jupyter Notebook 中的回溯?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68127608/

相关文章:

python - 在 pandas 数据系列中获取 NAN 索引的最佳方法是什么

python - 打印直方图

python - 使用 matplotlib 创建自己的颜色图并绘制颜色比例

python - Jupyter Notebook 在 Pycharm 中无法完全运行

python - 当文件在磁盘上更改时自动重新加载 jupyter notebook

ipython - 防止用户在 ipython-notebook 环境中删除文件

kotlin - 如何只显示错误而不显示调用堆栈跟踪?

python - 将 Scrapy 与 Javascript 和 iFrame 及替代品一起使用

python - 计算圆和直线的变换