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,使配置生效。
相关推荐
老师好,我是刘同学14 小时前
Python执行命令并保存输出到文件
python
送我上青云|16 小时前
告别繁琐命令行:VS Code CMake Tools 环境配置极简指南
ide·visual studio code
啵啵鱼爱吃小猫咪16 小时前
机械臂阻抗控制github项目-mujoco仿真
开发语言·人工智能·python·机器人
MaximusCoder16 小时前
等保测评命令——Centos Linux
linux·运维·经验分享·python·安全·centos
yunyun3212316 小时前
用Python生成艺术:分形与算法绘图
jvm·数据库·python
m0_6625779716 小时前
高级爬虫技巧:处理JavaScript渲染(Selenium)
jvm·数据库·python
songyuc17 小时前
【PyTorch】感觉`CrossEntropyLoss`和`BCELoss`很类似,为什么它们接收labels的shape常常不一样呢?
人工智能·pytorch·python
ℳ๓₯㎕.空城旧梦17 小时前
Python单元测试(unittest)实战指南
jvm·数据库·python
浩子智控18 小时前
python程序打包的文件地址处理
开发语言·python·pyqt
Jackey_Song_Odd18 小时前
Part 1:Python语言核心 - 序列与容器
开发语言·windows·python