本文介绍了如何在IPython Notebook中将自动缩进更改为2空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我发现在IPython Notebook中开发功能使我可以快速工作.当我对结果感到满意时,我会将其复制粘贴到文件中.自动缩进为4个空格,但我公司的缩进编码样式为2个空格.如何将自动缩进更改为2个空格?

I find that developing functions in IPython notebook allows me to work quickly. When I'm happy with the results I copy-paste to a file. The autoindent is 4 spaces, but the coding style for indentation at my company is 2 spaces. How do I change the autoindent to 2 spaces?

推荐答案

基于问题以及找到的选项此处:
在您的custom.js文件中(位置取决于您的操作系统)

Based on this question and the options found here:
In your custom.js file (location depends on your OS) put

IPython.Cell.options_default.cm_config.indentUnit = 2;

在我的机器上,文件位于~/.ipython/profile_default/static/custom

On my machine the file is located in ~/.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.indentUnit = 2;
            }
        );
    }
);

这篇关于如何在IPython Notebook中将自动缩进更改为2空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 21:16