Jupyter如何优雅禁止termin

修改前端 JavaScript

1、在 Jupyter 配置目录下创建一个自定义的 custom.js 文件:

复制代码
mkdir -p ~/.jupyter/custom 

touch ~/.jupyter/custom/custom.js

2、在 custom.js 文件中添加以下 JavaScript 代码来覆盖感叹号命令的行为:

复制代码
require(['base/js/namespace'], function(Jupyter) {
    var old_execute = Jupyter.notebook.kernel.execute;
    Jupyter.notebook.kernel.execute = function(code, callbacks, options) {
        if (code.trim().startsWith('!')) {
            console.warn('Usage of "!" for system commands is disabled.');
            return;
        }
        old_execute.call(this, code, callbacks, options);
    };
});
3、修改 Jupyter Notebook 配置文件 ~/.jupyter/nbconfig/notebook.json,包含对 custom.js的引用:
复制代码
{
  "load_extensions": {
    "custom/custom.js": true
  }
}
4、重启 Jupyter Notebook,使配置生效。
相关推荐
2401_8914504615 分钟前
Python上下文管理器(with语句)的原理与实践
jvm·数据库·python
helloworldandy16 分钟前
使用Python处理计算机图形学(PIL/Pillow)
jvm·数据库·python
2301_790300961 小时前
Python单元测试(unittest)实战指南
jvm·数据库·python
gusijin1 小时前
解决idea启动报错java: OutOfMemoryError: insufficient memory
java·ide·intellij-idea
吨~吨~吨~1 小时前
解决 IntelliJ IDEA 运行时“命令行过长”问题:使用 JAR
java·ide·intellij-idea
VCR__1 小时前
python第三次作业
开发语言·python
韩立学长1 小时前
【开题答辩实录分享】以《助农信息发布系统设计与实现》为例进行选题答辩实录分享
python·web
HAPPY酷1 小时前
为啥双击 .sln 文件即可在 Visual Studio 中加载整个解决方案
ide·visual studio
summer_du1 小时前
IDEA插件下载缓慢,如何解决?
java·ide·intellij-idea
2401_838472512 小时前
使用Scikit-learn构建你的第一个机器学习模型
jvm·数据库·python