1

I have found no method of clearing the terminal window from within a python script that does so without creating a huge empty space above the screen. I am writing a script that needs to periodically update the screen and doing so using os.system("clear") makes for a long scroll to see wherever you were before running the script. [edit] os.system("tput reset") also does this [/edit]

Edit: I forgot to mention which operating system I'm using, it's Mac OS X 10.10.

To clarify, I am not looking for just any way to clear the screen, I am looking for a way that is not functionally equivalent to hitting enter a bunch of times. (e.g. print("\n\n\n\n\n\n..."))

Arcuritech
  • 199
  • 1
  • 4
  • I don't understand your question. What do you mean by "huge empty space above the screen"? Isn't that what you want, if you are going to clear the screen? – Keith May 22 '16 at 22:55
  • Sounds like you should use the [curses](https://docs.python.org/3/library/curses.html) library. – Keith May 22 '16 at 22:58
  • How do you send a CMD+k through python script? – Arcuritech May 23 '16 at 22:18

1 Answers1

1

""" You can try:

os.system('tput reset')

To hide the return value, use:

variable = os.system('tput reset')

"""

as seen :: How to clear python console (i.e. Ctrl+L command line equivalent)

Or the answer to a similar question I actually asked a while back...

""" What you're looking for is:

print("{}/100".format(k), "\r", end="")

\r is carriage return, which returns the cursor to the beginning of the line. In effect, whatever is printed will overwrite the previous printed text. end="" is to prevent \n after printing (to stay on the same line).

In Python 2, the same can be achieved with:

print "{}/100".format(k), "\r",

""" as seen :: Unprint a line on the console in Python?

Community
  • 1
  • 1
kpie
  • 9,588
  • 5
  • 28
  • 50
  • I am looking for a way that is not functionally equivalent to hitting enter a bunch of times. Thanks for the effort though. – Arcuritech May 22 '16 at 22:51