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,
You can try Cell -> Current Outputs -> Toggle Scrolling in the Jupyter UI to enable the scrolling for the output of one cell.
To auto scroll a page from top to bottom we can use scrollTop() and height() method in jquery. In this method pass the document's height in scrollTop method to scroll.
Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.
Both ! and % allow you to run shell commands from a Jupyter notebook. % is provided by the IPython kernel and allows you to run "magic commands", many of which include well-known shell commands. ! , provided by Jupyter, allows shell commands to be run within cells.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With