Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 789
anon comp Avatar asked Nov 14 '21 20:11

anon comp


People also ask

How do you make a scrollable output in a Jupyter Notebook?

You can try Cell -> Current Outputs -> Toggle Scrolling in the Jupyter UI to enable the scrolling for the output of one cell.

How do you prevent the scrollable sub window in Jupyter notebooks?

To prevent scrolling within a single cell output, select the cell and press Shift+O while in command state. It will toggle output for that particular cell. If you want all the cells to display long outputs without scrolling, then go to the Cell tab -> All Outputs -> Toggle Scrolling . That's it !!!

Is Jupyter slower than Python?

I have found that Jupyter is significantly slower than Ipython, whether or not many print statements are used. Nearly all functions suffer decreased performance, but especially if you are analyzing large dataframes or performing complex calculations, I would stick with Ipython.


2 Answers

Try going to cell > current outputs > toggle scrolling in the Jupyter UI to enable scrolling output for a cell.

like image 113
Charlie Cook Avatar answered Oct 23 '22 23:10

Charlie Cook


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
like image 41
D Adams Avatar answered Oct 23 '22 22:10

D Adams