16

Is there a way to configure the ipython notebook so that whenever I print a long list, I automatically see the bottom?

for example, in the terminal, if I run the following:

for i in range(1000):
  print i

It automatically scrolls to the bottom:

992
993
994
995
996
997
998
999

In [2]: 

But in the Python notebook, I see the beginning and I have to manually scroll down to the last numbers.

I am running a long loop that takes a few seconds for each iteration, and it is inconvenient to have to scroll down whenever I want to check how far along the program is,

thank you,

dleal
  • 2,244
  • 6
  • 27
  • 49
  • Not a quick fix, but you could "theme" the python notebook template to include this functionality: http://stackoverflow.com/questions/18614301/keep-overflow-div-scrolled-to-bottom-unless-user-scrolls-up – Glenn Jan 09 '17 at 01:49

4 Answers4

14

Recommend: Tampermonkey plugin

(Once for all action!)
Copy & paste the following codes to any cell (or console,F12), run it.
After execution, you can delete the cell, then just continue your work!

%%javascript

window.scroll_flag = true
window.scroll_exit = false
window.scroll_delay = 100

$(".output_scroll").each(function() {
    $(this)[0].scrollTop = $(this)[0].scrollHeight;
});

function callScrollToBottom() {
    setTimeout(scrollToBottom, window.scroll_delay);
}

function scrollToBottom() {
    if (window.scroll_exit) {
        return;
    }
    if (!window.scroll_flag) {
        callScrollToBottom();
        return;
    };
    
    $(".output_scroll").each(function() {
        if (!$(this).attr('scroll_checkbox')){
            window.scroll_flag = true;
            $(this).attr('scroll_checkbox',true);
            var div = document.createElement('div');
            var checkbox = document.createElement('input');
            checkbox.type = "checkbox";
            checkbox.onclick = function(){window.scroll_flag = checkbox.checked}
            checkbox.checked = "checked"
            div.append("Auto-Scroll-To-Bottom: ");
            div.append(checkbox);
            $(this).parent().before(div);
        }
        
        $(this)[0].scrollTop = $(this)[0].scrollHeight;
    });
    callScrollToBottom();
}
scrollToBottom();

Or you can try jupyter_contrib_nbextensions's 'scroll-down' function.

scruel
  • 426
  • 6
  • 14
1

I use jupyter-notebook alot and didnt like that it didnt auto scroll to the bottom, so what I use is progressbar2, then you can do something like:

import progressbar
with progressbar.ProgressBar(max_value=1000) as bar:
    for idx, val in enumerate(range(1000)):
        bar.update(idx)

Then you will see one line output with more useful info like percentage complete, elapsed time, ETA,::

100% (1000 of 1000) |####################| Elapsed Time: 0:00:00 Time:  0:00:00
alexexchanges
  • 3,252
  • 4
  • 17
  • 38
1

Old question, but there is an extension in Jupyter Notebook called ScrollDown.

When enabled, this nbextension scrolls cells’ outputs down automatically as they are enlarged. It can be enabled and disabled using the toolbar button

Mehdi
  • 999
  • 13
  • 11
-1

I don't think there is a way to do this with iPython, however, if you use Pandas, you can use the tail function to print only the last records.

You can even import your data into Pandas from Python native tuples:

import pandas as pd
df = pd.DataFrame.from_records(list(range(1000), columns = (id,))

If you don't want to use Pandas, you can collect all items into a list and then only print the last 10 records:

print(list(range(1000))[-10])
bman
  • 5,016
  • 4
  • 36
  • 69