How do I reset the Jupyter/IPython input prompt numbering?

前端 未结 9 1096
孤街浪徒
孤街浪徒 2021-02-02 05:08

I just wrote my first extensive Python tutorial using IPython notebooks. All went well, except I did a lot of testing and moving blocks around. How do I reset the In [

9条回答
  •  深忆病人
    2021-02-02 05:39

    Every .ipynb file can be opened in an editor. Everything written there is in plain text (JSON). For each cell which has the "cell_type": "code" there'd be another key-value pair as "execution_count": . As you might have guessed, that is the prompt numbering. Hence, if the notebook contains code which will take time to execute (as was, in my case) this method would be time efficient.

    Now, either you can manually change each execution_count or write a simple script to get the numbering right. To check the results just refresh the notebook in the browser without stopping the kernel. And, everything will be as per your needs, even all the variables/loaded data will remain in the environment.

提交回复
热议问题