如何在IPython笔记本中阻止注释代码? [英] How can I block comment code in the IPython notebook?

查看:207
本文介绍了如何在IPython笔记本中阻止注释代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在IPython笔记本中定义了一个函数,并希望能够阻止对其中一部分的注释。直观地说,我希望能够突出显示一段代码,右键单击并选择注释掉选择,但这尚未实现。

I have defined a function in an IPython notebook and would like to be able to block comment a section of it. Intuitively, I'd expect to be able to highlight a section of code, right click and have an option to comment out the selection but this has not been implemented.

有没有办法做到这一点?

Is there a way to do this?

推荐答案

默认解决方案



在IPython 2.x和3中。 x (cmd | ctrl) - / 有效,但需要英文(美国)键盘布局,请参阅 https://github.com/ipython/ipython/pull/3673

Default solution

In IPython 2.x and 3.x (cmd|ctrl)-/ works but requires an english (american) keyboard layout, see https://github.com/ipython/ipython/pull/3673.

如果您使用非英语键盘布局,则可以通过custom.js为codemirror编辑器定义自定义键绑定。为此添加例如以下行

In case you have a non-english keyboard layout, you can define a custom keybinding for the codemirror editor via your custom.js. To this end add e.g. the following lines

define([
    'base/js/namespace',
    'base/js/events'
    ],
    function(IPython, events) {
        events.on("app_initialized.NotebookApp",
            function () {
                IPython.Cell.options_default.cm_config.extraKeys = {"Ctrl-," : "toggleComment"};
            }
        );
    }
);

使用 Ctrl + 来切换(块)评论。我使用德语键盘布局和IPython 3.0。
之前的解决方案(参见编辑)适用于chrome,但不适用于firefox。

to use Ctrl+, to toggle (block) comments. I use this with a german keyboard layout and IPython 3.0. The previous solution (see edits) worked fine with chrome, but not with firefox.

如果您使用的是IPython 1.x,您可以从 comment-uncomment.js .com / ipython-contrib / IPython-notebook-extensions> https://github.com/ipython-contrib/IPython-notebook-extensions - 我还没试过这个,但我觉得它很好开始。

If you are using IPython 1.x you can try the comment-uncomment.js from https://github.com/ipython-contrib/IPython-notebook-extensions - I haven't tried this yet, but I guess its a good start.

这篇关于如何在IPython笔记本中阻止注释代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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