2

With iPython, is there any way to clear output from all cells? I am looking for a command that can do it in one shot.

I see that clear_out like below can do the cleaning work, but it works for one single cell, not all:

from IPython.display import clear_output
clear_output(wait=True)
4
  • 1
    Are you asking how to do it programmatically? Because the UI command does exist, but the way it's called differs between UIs/IDEs Commented Sep 23 at 8:46
  • @PanagiotisKanavos yes, correct Commented Sep 23 at 8:47
  • Does this answer your question: stackoverflow.com/a/47774393/21452631 ? Commented Sep 23 at 8:53
  • @ASr thanks but unfortunately not Commented Sep 23 at 9:04

1 Answer 1

0

Pretty much suggest using jupyter nbconvert --clear-output --inplace my_notebook.ipynb.

Or:

from IPython.display import clear_output
import time

for i in range(5):
    clear_output(wait=True)  # Clears previous output before printing new
    print(f"Iteration {i+1}")
    time.sleep(1)

You cloud use this Python code above for clearing output dynamically within a code cell, often within loops or for displaying real-time updates.

Sign up to request clarification or add additional context in comments.

1 Comment

I think jupyter nbconvert --clear-output --inplace my_notebook.ipynb is close to what I want, but it will have problem when executing it in my_notebook.ipynb since it will overwrite the current open file, so you need to manually accept the overwritten action.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.