Clear terminal in Python [duplicate] Clear terminal in Python [duplicate] python python

Clear terminal in Python [duplicate]


A simple and cross-platform solution would be to use either the cls command on Windows, or clear on Unix systems. Used with os.system, this makes a nice one-liner:

import osos.system('cls' if os.name == 'nt' else 'clear')


What about escape sequences?

print(chr(27) + "[2J")


Why hasn't anyone talked about just simply doing Ctrl+L in Windows or Cmd+L in Mac.Surely the simplest way of clearing screen.