0

I don't know if it is possible, but I have a Jupyter notebook where I'd like to disable some cells in case of a whole run. That is, 'Run All' would jump over these cells and not trigger them, but they could still be used if ran alone (e.g. with Ctrl+Enter) without changing the code.

I know %%script false --no-raise-error does the trick, but you need to manually change a constant to re-enable the cells when you need them. Ideally, I'd not have to change anything in the code.

Thanks in advance!

7evy
  • 128
  • 8
  • It's simply done. I do it all the time. In large Notebooks I tend to have different parts of the notebook segregated and grouped for certain tasks. And sometimes these different tasks do not depend on another tasks. Or sometimes the different tasks may not need to run sequentially. Etc... So what I do is insert a cell above a group of cells (a task) and then enter a letter or something similar that causes this cell to generate a Jupyter Run error. All the cells below this error cell stop being Run. Then I move down below this group of tasked cells, and then select Run All Below. – Gray Nov 15 '21 at 06:08
  • That's useful, but it's not quite what I want to achieve. Your solution needs the 'separated' cells to be below the others, while ideally they would be scattered in between. I'm looking for a way to jump over a cell, in a way – 7evy Nov 15 '21 at 10:38
  • There isn't a "go to ... " command in Jupyter that I've heard of. And haven't used a go-to command in probably more than 20 years since basic. – Gray Nov 15 '21 at 17:51

1 Answers1

1

Your question resembles another question on here that I've answered recently. It's not the same question but I think my solution to that one actually works better for you. Here's the link to it and I hope it helps: https://stackoverflow.com/a/73978254/16264178

(PS I previously just copy-pasted my answer to the other question to here and that got flagged by a moderator. He was right that that wasn't best practice (answering different questions with the same answer verbatim). The recommendation though was to flag this thread as a duplicate of the other, which it isn't really. They're similar questions but my suggestion was a fairly imperfect solution to the other query, whereas I think it applies very well to the question in this thread. That's why I reposted my answer here with a link to the other one. That was the best thing I could see to do but people should feel free to enlighten me if they know better)

J_Code
  • 53
  • 5