Jupyter notebook: how to leave one cell out while 'run all'

て烟熏妆下的殇ゞ 提交于 2020-03-25 16:05:49

问题


I'm writing python using jupyter notebook and I have two cells that can influence each other.

I'm wondering is it possible to leave some certain cells out after I click Restart & Run All so that I can test the two cells independently?


回答1:


One option based on Davide Fiocco's answer of this post and that I just tested is to include %%script magic command on each cell you don't want to execute. For example

%%script false --no-raise-error
for i in range(100000000000000):
    print(i)



回答2:


If you put those two cells at the end of the page, you can run all cells above a certain cell with a single click.

That or you can put a triple-quote at the beginning and end of the two cells, then un-quote the cells to test them.




回答3:


One option is to create a parameter and run the cells accordingly

x = 1

# cell 1
if x == 1:
    // run this cell

# cell 2
if x != 1:
    // run the other cell

In this example, you will skip cell 2.



来源:https://stackoverflow.com/questions/60556163/jupyter-notebook-how-to-leave-one-cell-out-while-run-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!