tags:

views:

92

answers:

1

Hi to all

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?

+2  A: 

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"
Greg Hewgill
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
@Angelbit: I added a pure Python example.
Greg Hewgill