如何在ipython笔记本中启用换行 [英] How to enable line wrapping in ipython notebook

查看:87
本文介绍了如何在ipython笔记本中启用换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在ipython笔记本中启用换行。我用Google搜索没有结果,我在终端输入了ipython notebook --help。这为配置文件提供了大量配置命令,但没有换行。有谁知道ipnotebook是否具有此功能,如果有,如何启用它?
非常感谢您的帮助。谢谢。

I have been trying to enable line wrapping in ipython notebook. I googled it with no results and i typed ipython notebook --help in a terminal. This gives me a ton of configuration commands for a config file, but no line wrapping. Does anyone know if ipnotebook has this feature and if so how to enable it? Your help would be greatly appreciated. Thank you.

推荐答案

正如@Matt指出的那样,你必须配置CodeMirror以启用包装。

As @Matt pointed out you have to configure CodeMirror to enable wrapping.

但是,这可以通过简单地将以下行添加到 custom.js 来实现:

However, this can be achieved by simply adding the following line to your custom.js:

 IPython.Cell.options_default.cm_config.lineWrapping = true;

因此无需遍历所有单元格。
以类似的方式,您可以启用行号,设置缩进深度等(请参阅@Matt发布的其他选项链接)。你的 custom.js 的位置取决于你的操作系统(在我的Ubuntu机器上它是〜/ .ipython / profile_default / static / custom )。

So there is no need to loop through all the cells. In a similar fashion you can enable line numbers, set the indentation depth and so on (see the link posted by @Matt for other options). The location of your custom.js depends on your OS (on my Ubuntu machine it is ~/.ipython/profile_default/static/custom).

在IPython 3中,普通电话不再有效,因此,需要将设置放在适当的事件处理程序中。可能的解决方案可能如下所示:

In IPython 3 the plain call does not work any more, thus it is required to place the setting within an appropriate event handler. A possible solution could look like:

define([
    'base/js/namespace',
    'base/js/events'
    ],
    function(IPython, events) {
        events.on("app_initialized.NotebookApp",
            function () {
                IPython.Cell.options_default.cm_config.lineWrapping = true;
            }
        );
    }
);

这篇关于如何在ipython笔记本中启用换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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