PDA

View Full Version : 'Clear' for python interpreter??



7raTEYdCql
March 25th, 2009, 05:46 PM
Just as there is clear and reset which clears the screen of your terminal, is there anything similar for the python interpreter.
Or do i have to write a script for that also??
I have to keep exiting python and clearing the screen and then reenter.

elCabron
March 25th, 2009, 06:44 PM
In a terminal you could use Ctrl-L to "clear" the screen.

sujoy
March 25th, 2009, 07:30 PM
offtopic, but i will mention it anyways, :P
try out ipython (it got completions )

nvteighen
March 25th, 2009, 07:45 PM
Just as there is clear and reset which clears the screen of your terminal, is there anything similar for the python interpreter.
Or do i have to write a script for that also??
I have to keep exiting python and clearing the screen and then reenter.
What you need is terminal handling. In other words, ncurses...

http://docs.python.org/library/curses.html

Can+~
March 25th, 2009, 10:05 PM
Just as there is clear and reset which clears the screen of your terminal, is there anything similar for the python interpreter.
Or do i have to write a script for that also??
I have to keep exiting python and clearing the screen and then reenter.

clearing and reenter? Why don't just create a python script file? (.py)

crui-zer
July 28th, 2009, 08:46 PM
A very simple 2 line command
>>> import os - this can also help you call other os / system commands
>>>> os.system('cls')
This should clear the screen for python interpreter started on cmd prompt.

shadowh511
July 28th, 2009, 09:02 PM
A very simple 2 line command
>>> import os - this can also help you call other os / system commands
>>>> os.system('cls')
This should clear the screen for python interpreter started on cmd prompt.

but if you are on linux, its:


>>> os.system("clear")

my way of doing it would be



def clearScreen():
import os
os.system("clear")

JordyD
July 28th, 2009, 10:02 PM
A very simple 2 line command
>>> import os - this can also help you call other os / system commands
>>>> os.system('cls')
This should clear the screen for python interpreter started on cmd prompt.

You are obviously not using Ubuntu. 'cls' is a valid command for the Windows command prompt, but this is an Ubuntu forums, so I imagine that the poster is using Ubuntu, and in that case you would use os.system('clear') as someone else mentioned.

But still, that's not portable. You can do something like this:

import platform
import os
if platform.system() == 'Windows':
os.system('cls')
else:
os.system('clear')

or you can do something like this, though it's sort of hack-ish:

print '\n' * 100

It of course will break if you have a lot of lines in your terminal.

Unixarcade
May 16th, 2011, 07:02 PM
I came to the forum because I was looking for this solution and the code worked thank you for all of your hard work.

cgroza
May 16th, 2011, 09:08 PM
but if you are on linux, its:


>>> os.system("clear")my way of doing it would be



def clearScreen():
import os
os.system("clear")


It is not recommended to import modules in a function that you will run several times.
EDIT: Sorry, did not see this thread dates from 2009.

7raTEYdCql
May 17th, 2011, 07:55 AM
On ipython !clear does the job. Thanks for your responses everyone.