0

How do I clear the screen for the Python Shell?

I am using Python 3.7.2. I know there is a code for clearing the screen in the Python for Windows Terminal. Someone told me to type in "cls" but that returns an error message:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    cls
NameError: name 'cls' is not defined
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Mick Kelly
  • 101
  • 1
  • Easiest but hackiest way is probably to do `import os; a = os.system("cls");` This just calls out to the shell and runs whatever is in quotes. – lvrf Apr 19 '20 at 01:08

1 Answers1

0

You can issue a sub-process call to cls or clear depending on your OS.

import subprocess
subprocess.call('cls')

Alternatively if you're looking to clear the shell without code you can use Control-L.

zevra0
  • 209
  • 1
  • 5