3

I'm need to create a Python shell script that refresh output every n seconds like top unix command. what 's the best way to do this?

1
  • 2
    For a pure-python solution you'll probably want to use the curses module. I haven't used it myself but have heard that it's a bit complicated and tricky to use. Commented Sep 26, 2010 at 23:23

1 Answer 1

4

One way to do this is to write a script that prints your output (once), and then run your script using the watch command. The watch command will automatically clear the screen and run your script every few seconds (usually 2 by default).

If you really want to do this in pure Python, you can use the curses module, or if you know your terminal is VT100-compatible you can go considerably simpler:

print "\x1b[H\x1b[2J",
print "hello clear world"
Sign up to request clarification or add additional context in comments.

2 Comments

this command seems use a "fullscreen" shell, is not possible to implement this with python? (and relative clear method)...in this manner have the possibility to implement a cache system (my script is based to various REST API) without recall all every "refresh"
@Angelbit: I added a pure Python example.

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.