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 c开发者_C百科lear 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?
solved the issue with:
import curses
window = curses.initscr()
window.addstr(1, 0, "my text")
window.refresh()
curses.endwin()
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')
For simple applications you can use:
print('\n' * number_of_lines)
For more advanced there is curses module in standard library.
精彩评论