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.
14 Answers
from IPython.display import clear_output clear_output() 0You 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
Instead of running
!python file.py You can use this.
%run file.py And it will work as expected.
IPython is for Jupyter mainly and it should work in Colab for a local file if implemented correctly. Don't forget to import the library in the main python code.