I have just migrated from Jupyter to Spyder. On the left of the screen there is a console that shows the output. When I rerun the code it keeps adding new lines. I want to start with a new screen. How?
PS1: When I go to the IPyhton console and write cls or clear, it works. But I want to do that from Python code. The latter doesn't recognize that command, but IPython console does!
PS2: I've tried
import os
os.system('cls') # on windows
It didn't work. It shows a CMD window for a moment and vanishes. But the console window in Spyder still shows the old errors, besides the new ones.
Windows Spyder 4, Python 3.7:
!clsclscls()Ctrl + Lclearclear()print(chr(27) + "[2J")print("\x1b[2J")clear-screenWindows Terminal, Python 3.9:
!clsclsCtrl + Lcls()print(chr(27) + "[2J")print("\x1b[2J")Linux Terminal, Python 3.8:
Ctrl + Lclear(Spyder maintainer here) There are two ways to get what you want:
Run > Configuration per file and select the option called Execute in a dedicated console. That option will clean your console after every execution.Add the following code to your file:
from IPython import get_ipython
get_ipython.run_line_magic('clear', '')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With