How to run Python code before every jupyter notebook kernel

前端 未结 1 608
鱼传尺愫
鱼传尺愫 2021-01-18 20:17

Suppose I have a code snippet that I\'d like to run every time I open a jupyter notebook (in my case it\'s opening up a Spark connection). Let\'s say I save that code in a .

相关标签:
1条回答
  • 2021-01-18 20:32

    I'd recommend to create a startup file as you suggested, and include it via

    %load ~/.jupyter/startup.py
    

    This will paste the content of the file into the cell, which you can then execute.

    Alternatively, you can write a minimal, installable package that contains all your startup code.

    Pro: Doesn't clutter your notebook

    Con: More difficult to make small changes.

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