[翻译]  Choose SQL as default cell magics for Jupyter Notebook

[CHINESE]  选择SQL作为Jupyter Notebook的默认单元格魔术


I'm writing a Jupyter notebook for a database course; most cells will contain SQL code, for which I use the IPython SQL magic. Currently I have to prepend each cell with %%sql. Is there a way to avoid typing %%sql before each cell, by making it the default?

我正在为一个数据库课程写一个Jupyter笔记本;大多数单元格将包含SQL代码,我使用IPython SQL魔术。目前我必须在每个单元格前加上%% sql。有没有办法避免在每个单元格之前键入%% sql,使其成为默认值?

I found a related question at How do I set up default cell magics for every ipython notebook cell?. However, I couldn't find a SQL kernel for Jupyter.

我在如何为每个ipython笔记本电脑单元设置默认单元格魔术中找到了一个相关问题?但是,我找不到Jupyter的SQL内核。

1 个解决方案

#1


4  

The Jupyter docs tell you how you can edit the CodeMirror settings. CodeMirror has an option called value that determines the default value of a CodeMirror cell (doc link).

Jupyter文档告诉您如何编辑CodeMirror设置。 CodeMirror有一个名为value的选项,用于确定CodeMirror单元的默认值(doc链接)。

So, in ~/.jupyter/nbconfig/notebook.json paste in the following code:

所以,在〜/ .jupyter / nbconfig / notebook.json中粘贴以下代码:

{
    "CodeCell": {
        "cm_config": {
            "value": "%%sql"
        }
    }
}

and now every new cell will have %%sql in it. Obviously this solution applies to any cell magic or indeed any default value you may want your code cells to have.

现在每个新单元格中都有%% sql。显然,此解决方案适用于任何单元格魔法或您可能希望代码单元具有的任何默认值。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号