Configure a first cell by default in Jupyter notebooks

后端 未结 6 566
再見小時候
再見小時候 2021-02-02 01:03

TIs there a way to configure a default first cell for a specific python kernel in the Jupyter notebook? I agree that default python imports go against good coding practices.

6条回答
  •  借酒劲吻你
    2021-02-02 02:01

    An alternative which I find to be quite handy is to use %load command in your notebook.

    As an example I stored the following one line code into a python file __JN_init.py

    import numpy as np
    

    Then whenever you need it, you could just type in:

    %load __JN_init.py
    

    and run the cell. You will get the intended package to be loaded in. The advantage is that you could keep a set of commonly used initialization code with almost no time to set up.

提交回复
热议问题