SoFunction
Updated on 2024-12-10

jupyter notebook clears the output method

existjupyter notebook parameterized to run pythonWhen I want to clear the output of notebook in time, I am afraid that the output file will be too large.

I've seen easydl's clear_output() used in other people's code. It's easy to call:

from easydl import clear_output

print('before')
clear_output() # Clear the output
print('after')

Check its source code:clear_output

def clear_output():
  """
  clear output for both jupyter notebook and the console
  """
  import os
  ('cls' if  == 'nt' else 'clear')
  if is_in_notebook():
    from  import clear_output as clear
    clear()

The output of the terminal/console is cleared by the clear/cls command of the system.

The output of notebook is cleared with .clear_output().

One of them is_in_notebook() is also a function of easydl to determine if it is in notebook.

Check its source code:is_in_notebook

def is_in_notebook():
  import sys
  return 'ipykernel' in 

Additional knowledge:How to remove the Run button in front of the input field in Jupyter notebook?

If you've run into this recently while using Jupyter notebook:

In[ ] has an extra run symbol after it, which makes it obtrusive that In[ ] and Out[ ] are no longer aligned. So this blog is for you, Let's go!

First, let's find out why. This thing appears because there is a CSS property behind it that controls the display of this unit, use edge (or another browser) to view the element running the icon:

Note the CSS property display: block, which controls the display of the Run button. If you change it to display: none, the Run button disappears, so let's see the effect.

The annoying Run button has disappeared. So, you already know how to fix it, just change the value of the corresponding property in the CSS file, which is located here [ your anaconda installation path ]\Lib\site-packages\notebook\static\

Open it, you should have VSCode, then use it to open the

Go to line 10661 and change it to display: none

Now that you're done, refresh your notebook page to see the results.

Of course, you can also modify the corresponding CSS file to change the input code font size, font style, output font size, etc. in the notebook.

Above this jupyter notebook to clear the output method is all that I have shared with you, I hope to give you a reference, and I hope you will support me more.