Clear the terminal window.

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Gribouillis Gribouillis is offline Offline Oct 26th, 2009, 1:14 pm |
0
Printing a convenient ansi escape sequence clears the terminal (if you're running python from a terminal). Similar techniques could be used to print in colors.
Last edited by Gribouillis; Oct 26th, 2009 at 1:32 pm.
Quick reply to this message  
Python Syntax
  1. def clear():
  2. print("\x1B[2J")
  3.  
  4. clear()
0
vegaseat vegaseat is offline Offline | Oct 26th, 2009
Linux only?
 
0
Gribouillis Gribouillis is offline Offline | Oct 26th, 2009
No, with ANSI.SYS, it should work on windows too.
 
0
Gribouillis Gribouillis is offline Offline | Oct 27th, 2009
Correction: you were right, I couldn't make it work on windows. The ANSI.SYS driver works only with very old versions of windows. You would need a terminal emulator similar to the linux console. There is a module console for windows, with slightly different control sequences. See if it works with your versions of windows/python.

So let's say it's linux only...
Last edited by Gribouillis; Oct 27th, 2009 at 12:02 pm.
 
 

Tags
ansi, clear, terminal

Message:


Thread Tools Search this Thread



Tag cloud for ansi, clear, terminal
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC