Choose SQL as default cell magics for Jupyter Notebook

后端 未结 1 994
感动是毒
感动是毒 2021-02-04 10:37

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

相关标签:
1条回答
  • 2021-02-04 10:59

    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).

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

    {
        "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.

    0 讨论(0)
提交回复
热议问题