Page 1 of 1

How do I clear the Console Screen

Posted: Sun Apr 21, 2013 2:38 pm
by dawson345
Hi, I would like to clear the terminal window to display sensor readouts.

I used to use console.clear on VB.

Re: How do I clear the Console Screen

Posted: Sun Apr 21, 2013 2:42 pm
by dawson345
Sorry
it's

Code: Select all

import os

os.system('clear')
from http://stackoverflow.com/questions/1432 ... thon-shell

Re: How do I clear the Console Screen

Posted: Sun Apr 21, 2013 2:51 pm
by PS1981
Your method however doesn't actually clear the console screen, it just pushes everything out of sight. try this for comparision:

Code: Select all

os.system('printf "\033c"')
or simply (python3 example)

Code: Select all

print ("\033c")

Re: How do I clear the Console Screen

Posted: Sun Apr 21, 2013 3:12 pm
by jojopi
PS1981 wrote:Your method however doesn't actually clear the console screen, it just pushes everything out of sight.
Do you have the correct TERM setting?

"clear" should send "\033[H\033[2J", which homes the cursor and then clears the whole screen. "\033c" is a full reset, which is slower and more comprehensive, but should not normally look different.

Re: How do I clear the Console Screen

Posted: Sun Apr 21, 2013 3:17 pm
by PS1981
Don't know to be honest. Just works for me as described.

Re: How do I clear the Console Screen

Posted: Sun Apr 21, 2013 3:35 pm
by SN
oh the wonders of ANSI escape codes.... takes me straight back to 1990

Full list here, out of interest
http://en.wikipedia.org/wiki/ANSI_escape_code

Re: How do I clear the Console Screen

Posted: Sun Apr 21, 2013 3:40 pm
by PS1981
SN wrote:oh the wonders of ANSI escape codes.... takes me straight back to 1990
when I were a lad... :D

I was just trying some stuff out anyway, it appears (to me at least) that if you are really in the console "clear" does what is required. The use of "clear" however when in a terminal window of the x desktop leaves the option of scrolling up with the scroll bar at the side. It depends what the OP is up to. If clear is somehow quicker or uses less resources and is at the same time adequate, then that's fine.

Re: How do I clear the Console Screen

Posted: Sun Apr 21, 2013 4:51 pm
by dawson345
Thanks guys :)

Re: How do I clear the Console Screen

Posted: Sun Apr 21, 2013 5:38 pm
by jojopi
On the console you can still scroll up after both clear and reset. There is no scroll bar of course, but the keystroke is the same: Shift+PageUp. Personally I would find it mildly irritating if a program cleared the scrollback without a good reason.

I was mistaken about the speed difference, though. The noticeable pause when running "reset" is a feature of that program rather than the escape sequence itself.

Re: How do I clear the Console Screen

Posted: Wed Apr 05, 2017 8:40 pm
by bcbrown
When u use this it prints a random Integer. Any comments?