How to Clear Python Output Programatically in Goog

2020-07-13 07:43发布

问题:

This question is specific to Google Colaboratory, while some solutions may work in a normal Python interperter, Google Colaboratory does not seem to allow me to programatically clear the Python interpreter output.

Solutions that I have already tried that do not work:

import os
os.system('cls')
os.system('clear')
!cls
!clear

回答1:

from IPython.display import clear_output clear_output()

This is useful to me.



回答2:

This snippet will halt the current Python runtime and reconnect to a fresh one. (Your filesystem will remain intact.)

import os
os.kill(os.getpid(), 9)