tags:

views:

41

answers:

3

Hello,

I have a stats app written in python that on a timer refreshes the ssh screen with stats. Right now it uses os.system('clear') to clear the screen and then outputs a multi line data with the stats.

I'd like to do just do a \r instead of executing the clear but that only works with one line, is it possible to do this with multiple lines?

A classic example of what I want to do is when you execute the "top" command which lists the current processes it updates the screen without executing the "clear" and it's got many lines.

Anyone have any tips for this?

+1  A: 

It doesn't really answer your question, but there isn't really anything wrong with calling os.system to clear out the terminal (other than the system running on different operating systems) in which case you could use:

os.system('cls' if os.name=='nt' else 'clear')

Tim
The appropriate function in the subprocess module should be used instead of os.system.
Florian Mayer
A: 

For simple applications you can use:

print('\n' * number_of_lines)

For more advanced there is curses module in standard library.

Michał Niklas
that obviously works however I don't want to just clear the screen by writing new lines, all I want is the current screen to be updated. Exactly like how the "top" command works on linux, just updates the current screen without clearing the screen.
Joe
A: 

solved the issue with:

import curses
window = curses.initscr()
window.addstr(1, 0, "my text")
window.refresh()
curses.endwin() 
Joe