How to clear the output in Google Colab via code?
11,507
Solution 1
from IPython.display import clear_output
clear_output()
Solution 2
You can use this in a javascript console to clear output every 1 minute:
function ClearOutput(){
console.log("Cleared Output");
document.querySelector("iron-icon[command = 'clear-focused-or-selected-outputs']").click()
}
setInterval(ClearOutput,60000)
Note that the code block for which you wish to clear the output has to be in focus. For this you can click on the following icon (shown in the image link below) when the desired cell is running:
The three dots focus on the currently running cell
Author by
Admin
Updated on June 21, 2022Comments
-
Admin almost 2 years
I want to periodically clear the output of a cell in Google Colab, which runs a local python file with
!python file.py
I've tried the answers to this question on stackoverflow:
from google.colab import output output.clear()
and
from IPython.display import clear_output clear_output()
Both of those work if i run them in a cell directly and not via a local file.