在ipython Notebook中自动向下滚动到结果底部 [英] Automatic scroll down to bottom of result in ipython notebook

查看:103
本文介绍了在ipython Notebook中自动向下滚动到结果底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以配置ipython笔记本,以便每当打印长列表时,我都会自动看到底部?

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

它会自动滚动到底部:

992
993
994
995
996
997
998
999

In [2]: 

但是在Python笔记本中,我看到了开始,并且我必须手动向下滚动到最后一个数字.

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,

谢谢

推荐答案

(一旦执行所有操作!)
复制和将以下代码粘贴到任何单元格(或控制台,F12),运行它.
执行后,您可以删除单元格,然后继续您的工作!

(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();

或者您可以尝试 jupyter_contrib_nbextensions 的向下滚动"功能.

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

这篇关于在ipython Notebook中自动向下滚动到结果底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆