944,142 Members | Top Members by Rank

Ad:
  • Python Code Snippet
  • Views: 3751
  • Python RSS
0

Clear the terminal window.

by on Oct 26th, 2009
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.
Python Code Snippet (Toggle Plain Text)
  1. def clear():
  2. print("\x1B[2J")
  3.  
  4. clear()
Comments on this Code Snippet
Oct 26th, 2009
0

Re: Clear the terminal window.

Linux only?
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Oct 26th, 2009
0

Re: Clear the terminal window.

No, with ANSI.SYS, it should work on windows too.
Posting Maven
Gribouillis is offline Offline
2,656 posts
since Jul 2008
Oct 27th, 2009
0

Re: Clear the terminal window.

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.
Posting Maven
Gribouillis is offline Offline
2,656 posts
since Jul 2008
Message:
Previous Thread in Python Forum Timeline: Getting a tuple to return values.
Next Thread in Python Forum Timeline: Newbie Help with Pizza Programming Project





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC