1

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?

dyluns
  • 123
  • 7

3 Answers3

3

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)
datapug
  • 1,991
  • 1
  • 12
  • 30
1

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.

katardin
  • 581
  • 3
  • 14
1

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.

smttsp
  • 3,651
  • 3
  • 32
  • 59