

def clear(rows=-1, rows_max=None, *, calling_line=True, absolute=None,Ĭlear(0, -1) # Restore auto-determining rows_maxĬlear(calling_line=False) # Don't clear calling lineĬlear(absolute=5) # Absolutely clear out to 5 rows up"""Įlif not store_max or store_max or rows_max = -1 or absolute:Ĭolumns_max, rows_max = get_terminal_size() Gives you complete control over how much to clear. It gives you a CLEAN PROMPT rows_max distance from the bottom of the terminal, but also precisely from where it was called. This function works in gnome-terminal because, by default, it recognizes ANSI escape sequences.

It does use the os.system() command so if that's evil and someone knows a way of implementing this using subprocess.call() please comment as I would also prefer to use subprocess but am not familiar with it at all. Print('A bunch of garbage so we can garble up the screen.') No one has provided a true answer to OP question it seems, everyone either responds with 'NO DONT USE os.system() it's evil!!!' without explanation or provides a solution that relies on printing new lines.įor those that need to clear the terminal screen and scroll back, for whatever reason, you can use the following code: import osĬlears the terminal screen and scroll back to present So just thought I would throw my two cents in here.
