use*_*610 31 auto-indent ipython-notebook
我发现在IPython笔记本中开发函数可以让我快速工作.当我对结果感到满意时,我会将其复制粘贴到文件中.autoindent是4个空格,但我公司缩进的编码风格是2个空格.如何将autoindent更改为2个空格?
Ada*_*mAL 31
官方文档有一个例子来回答这个具体问题.这对我来说非常适合IPython 4.
摘要:将以下内容粘贴到浏览器的javascript控制台中
var cell = Jupyter.notebook.get_selected_cell();
var config = cell.config;
var patch = {
CodeCell:{
cm_config:{indentUnit:2}
}
}
config.update(patch)
Run Code Online (Sandbox Code Playgroud)
该设置是持久的.您可以回滚通过交换: 2的: null.
Tho*_*ran 21
从CodeMirror Code Cells的官方文档:
b片段:
var cell = Jupyter.notebook.get_selected_cell();
var config = cell.config;
var patch = {
CodeCell:{
cm_config:{indentUnit:2}
}
}
config.update(patch)
Run Code Online (Sandbox Code Playgroud)
F5这将永久修复它.我认为这仅适用于最新版本,但不确定!
bpi*_*rvu 15
AdamAL的回答是正确的.它对我有用.
但是它只会更改Jupyter Notebook中的缩进,并使Jupyter Editor中的缩进不受影响.
更改缩进的更直接方法是直接编辑.jupyter/nbconfig目录中的Jupyter配置文件.该目录包含2个文件:
edit.json
notebook.json
Run Code Online (Sandbox Code Playgroud)
您必须在任何一个中设置的选项是indentUnit.这是我的Jupyter配置文件的内容:
edit.json:
{
"Editor": {
"codemirror_options": {
"indentUnit": 2,
"vimMode": false,
"keyMap": "default"
}
}
}
Run Code Online (Sandbox Code Playgroud)
notebook.json:
{
"CodeCell": {
"cm_config": {
"indentUnit": 2
}
}
}
Run Code Online (Sandbox Code Playgroud)
通过这种方法,我在Jupyter Notebook和Jupyter Editor中都将默认缩进设置为2.
Jak*_*kob 11
根据这个问题和这里找到的选项:
在你的custom.js文件(位置取决于你的操作系统)放
IPython.Cell.options_default.cm_config.indentUnit = 2;
在我的机器上,文件位于 ~/.ipython/profile_default/static/custom
在IPython 3中,普通调用不再起作用,因此需要将该设置放在适当的事件处理程序中.可能的解决方案看起来像
define([
'base/js/namespace',
'base/js/events'
],
function(IPython, events) {
events.on("app_initialized.NotebookApp",
function () {
IPython.Cell.options_default.cm_config.indentUnit = 2;
}
);
}
);
Run Code Online (Sandbox Code Playgroud)
Tim*_*rks 10
我相信这现在最好包装在一个事件处理程序中,每个笔记本加载一次加载:
$([IPython.events]).on('app_initialized.NotebookApp', function(){
IPython.CodeCell.options_default['cm_config']['indentUnit'] = 2;
});
Run Code Online (Sandbox Code Playgroud)
如果您使用jupyterlab,似乎有一种更简单的方法:
1)点击jupyterlab菜单设置>高级设置编辑器
2) 单击左侧窗格中的“笔记本”,确保您处于“原始视图”
3) 在右窗格中的“用户覆盖”下,输入:
{
"codeCellConfig": {
"tabSize": 2
}
}
Run Code Online (Sandbox Code Playgroud)
如果您查看系统默认值,它会提示您什么是可覆盖的,您可以对其他设置重复此操作。
我在使用 Jupyterlab 的 Google Platform AI Notebook 上尝试过这个。
| 归档时间: |
|
| 查看次数: |
17067 次 |
| 最近记录: |