【问题标题】:Is there a way to make python showtraceback in jupyter notebooks scrollable?有没有办法让 jupyter notebooks 中的 python showtraceback 可以滚动?
【发布时间】:2021-12-26 04:59:37
【问题描述】:

或者如果有内置的滚动功能,来编辑滚动设置?

我试过了,但是没用--

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-notebook 中遇到错误时查看完整输出

标签: python scroll jupyter-notebook styling


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    如果您没有看到足够的回溯信息,您可以随时直接打印:

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

    产生:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      相关资源
      最近更新 更多