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..."))

3
  • 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? Commented May 22, 2016 at 22:55
  • Sounds like you should use the curses library. Commented May 22, 2016 at 22:58
  • How do you send a CMD+k through python script? Commented May 23, 2016 at 22:18

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

1 Comment

I am looking for a way that is not functionally equivalent to hitting enter a bunch of times. Thanks for the effort though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.