how to clear the screen in python


Possible Duplicates:
clear terminal in python
How to clear python interpreter console?

I'm trying to write a program in Python but I don't know how to clear the screen. I use both Windows and Linux and I use commands to clear the screen in those, but I don't know how to do it in Python.

How do I use Python to clear the screen?

5/23/2017 11:47:30 AM

Accepted Answer

What about escape sequences?

print(chr(27) + "[2J")
1/21/2015 8:35:15 PM

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 os
os.system('cls' if == 'nt' else 'clear')

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow