如何在 IPython 笔记本中将自动缩进更改为 2 个空格 [英] How do I change the autoindent to 2 space in IPython notebook

查看:23
本文介绍了如何在 IPython 笔记本中将自动缩进更改为 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?

推荐答案

基于this问题和找到的选项此处:
在您的 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 笔记本中将自动缩进更改为 2 个空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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