简体   繁体   English

有没有办法让 jupyter 笔记本中的 python showtraceback 可滚动?

[英]Is there a way to make python showtraceback in jupyter notebooks scrollable?

Or if there are scrolling functionalities built in, to edit the scrolling settings?或者如果有内置的滚动功能,编辑滚动设置?

I tried this but it didn't work --我试过这个,但没有用——

def test_exception(self, etype, value, tb, tb_offset=None):
    try:
        announce = Announce(etype, value)
        if announce.print:
            announce.title()
            announce.tips()
            announce.resources()
            announce.feedback()
            announce.scroll(self, etype, value, tb, tb_offset)
        #self.showtraceback((etype, value, tb), tb_offset=tb_offset)
    except:
        self.showtraceback((etype, value, tb), tb_offset=tb_offset)
    def scroll(self, etype, value, tb, tb_offset=None):
        b=widgets.HTML(
        value=self.showtraceback((etype, value, tb), tb_offset=tb_offset),
        placeholder='Some HTML',
        description='Some HTML',
        disabled=True
        )
        a = HBox([b], layout=Layout(height='20px', overflow_y='10px'))
        display(a)

尝试在 Jupyter UI 中转到cell > current outputs > toggle scrolling以启用单元格的滚动输出。

If you aren't seeing enough traceback information, you can always print it directly:如果您没有看到足够的回溯信息,您可以随时直接打印:

import traceback
try: 
    raise Exception('thing')
except:
    TraceBackString = traceback.format_exc()
    print(TraceBackString)

produces:产生:

 Traceback (most recent call last): File "yourfilehere", line 19, in <module> raise Exception('thing') Exception: thing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM