python自动调整缩进_如何在IPython Notebook中将自动缩进更改为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?

解决方案

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;

On my machine the file is located in ~/.ipython/profile_default/static/custom

Update:

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;

}

);

}

);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值