How to cache in IPython Notebook?

前端 未结 4 1116
借酒劲吻你
借酒劲吻你 2021-02-07 05:30

Environment:

  • Python 3
  • IPython 3.2

Every time I shut down a IPython notebook and re-open it, I have to re-run all the cells. But some cells

4条回答
  •  后悔当初
    2021-02-07 06:03

    Unfortunately, it doesn't seem like there is something as convenient as an automatic cache. The %store magic option is close, but requires you to do the caching and reloading manually and explicitly.

    In your Jupyter notebook:

    a = 1
    %store a
    

    Now, let's say you close the notebook and the kernel gets restarted. You no longer have access to the local variables. However, you can reload the variables you've stored using the -r option.

    %store -r a
    print a # Should print 1
    

提交回复
热议问题