Skip to content

Instantly share code, notes, and snippets.

@novaTopFlex
Created April 25, 2024 18:37
Show Gist options
  • Save novaTopFlex/b7af5286dd105959ce58fd5845a83bfc to your computer and use it in GitHub Desktop.
Save novaTopFlex/b7af5286dd105959ce58fd5845a83bfc to your computer and use it in GitHub Desktop.
Clear the Screen in a Python Interpreter

Clearing the Interpreter

There are multiple solutions to clearing the Python interpreter.

With os

With the os module, the code is as follows:

import os
os.system("clear")

The os.system() function will perform the applicable shell command with the default interpreter, often as /bin/sh.

With clear

To install the clear module:

pip install clear

After the clear module is successfully installed, the initial functions will be clear.clear() and the os module functions wrapped under clear.os. To clear the interpreter, you must type clear.clear() (with no arguments).

With the keyboard

On a terminal emulator (most likely not on IDLE, which is not a terminal interface): Control-L (^L)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment