jupyter-notebook - 如何在我的 Jupyter 笔记本中配置缩进大小?

标签 jupyter-notebook jupyter

我想在我的 Jupyter 笔记本中使用 2 个空格而不是 4 个空格的默认缩进大小。我怎样才能做到这一点?

注意:这不是 How do I change the autoindent to 2 space in IPython notebook 的副本,因为该问题针对(已弃用)IPython 笔记本而不是(当前)Jupyter 笔记本。

最佳答案

正确的方法是在 bpirvu 对 How do I change the autoindent to 2 space in IPython notebook 的隐藏答案中:

只需编辑 ~/.jupyter/nbconfig/notebook.json 。这是一个完整的 notebook.json,其中包括相关设置:

{
  "CodeCell": {
    "cm_config": {
      "indentUnit": 2
    }
  }
}

还有一个在网络上更流行的更hacky 的解决方案,可能是因为 Jupyter 文档缺乏关于此主题的内容,而 indentUnit 仅在此处提及: http://jupyter-notebook.readthedocs.io/en/latest/frontend_config.html 。此解决方案是打开浏览器的 JavaScript 控制台并输入
var cell = Jupyter.notebook.get_selected_cell();
var config = cell.config;
var patch = {
      CodeCell:{
        cm_config:{indentUnit:2}
      }
    }
config.update(patch)

最终会为您编辑 ~/.jupyter/nbconfig/notebook.json

关于jupyter-notebook - 如何在我的 Jupyter 笔记本中配置缩进大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40800349/

相关文章:

IPython(Jupyter)笔记本在所有方程中产生鬼线

python - 在 jupyter notebook 中编辑代码缩进的快捷方式

python - 在 Python matplotlib 中保留尺寸的同时提高图形的分辨率

cmd - Windows 中 Cmd 行的 Jupyter

python - ipython 中的制表符完成列表元素

python - 调用另一个脚本时,jupyter 中不显示日志输出

python - 处理时的 Jupyter Notebook 计数器

python - 为什么我会收到 NameError : name 'train_test_split' is not defined?

python - 如何使用 .loc 根据日期字段进行过滤

python - 一旦另一个单元完成,就评估一个单元