默认情况下如何在 IPython Notebook 代码单元格中显示行号 [英] How to display line numbers in IPython Notebook code cell by default

查看:25
本文介绍了默认情况下如何在 IPython Notebook 代码单元格中显示行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 IPython 笔记本代码单元格的默认显示包含行号.

I would like my default display for IPython notebook code cells to include line numbers.

我从 在 IPython/Jupyter Notebooks 中显示行号 中了解到,我可以用ctrl-ML,这很棒,但是是手动的.为了默认包含行号,我需要在 ipython_notebook_config.py 文件中添加一些内容.除非我遗漏了什么,否则文档中没有解释如何做到这一点.

I learned from Showing line numbers in IPython/Jupyter Notebooks that I can toggle this with ctrl-M L, which is great, but manual. In order to include line numbers by default, I would need to add something to my ipython_notebook_config.py file. Unless I've missed something, there is not an explanation of how to do this in the documentation.

推荐答案

在您的 custom.js 文件(位置取决于您的操作系统)中放入

In your custom.js file (location depends on your OS) put

IPython.Cell.options_default.cm_config.lineNumbers = true;

如果你找不到custom.js,你可以搜索它,但通常它会在你的profile_default文件夹中.如果它不存在,请在 $(ipython locate profile)/static/custom/custom.js

If you can't find custom.js, you can just search for it, but generally it will be in your profile_default folder. If it doesn't exist, create the file at $(ipython locate profile)/static/custom/custom.js

如果由于某种原因不起作用,您可以随时编辑 site-packages/IPython/html/static/custom/ 中的 custom.js 文件以同样的方式.

If for whatever reason that doesn't work, you can always edit the custom.js file in the site-packages/IPython/html/static/custom/ in the same way.

这篇关于默认情况下如何在 IPython Notebook 代码单元格中显示行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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