Thursday, 23 October 2014

Cleaning the Python Terminal

This article is about the different methods that can be used to clear the python terminal

The first method is like this,

Ubuntu :
 import os
 os.system('clear')    


Windows:
import os
os.system('cls')




Second Method:

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

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

Note that this method is only for ANSI Terminals.

27 is the decimal representation of the escape key. So ESC[2J is recognized as ANSI clear command.

Third Method

just keep printing new lines like

print '\n' * 80

No comments:

Post a Comment