By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

Clearing the screen

P: n/a
Hi i use IDLE to code Python in my machine. What i haven't been able
to do is call an in-built function called clear()/cls()/clr() because
it mightn't exist. so what i did is coded my own function called cls()
as such
def cls():

for i in range(1,40):
print " ";

now that does the job very nicely and i get cleared screen but what i
really want to achieve it everytime i start IDLE, without importing
any module, i want to be able to do just cls() and be able to clear
the screen. Is that achievable? Does that have mean i have to tinker a
bit with in-builts??

Thank you.

--
cheers,
Ishwor Gurung
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Iswor,

If I understand you correctly then your program is writing output to a
console/terminal window and you want to clear that window.
I don't know of any library methods for that, but you might just do:

os.system("cls") #for windows
or
os.system("clear") #for unix
Not the most advanced solution though.
---
Happy holidays!
~Lars

Jul 18 '05 #2

P: n/a
On 24 Dec 2004 15:33:26 -0800, Lars <la******@lycos.com> wrote:
Hi Iswor,

If I understand you correctly then your program is writing output to a
console/terminal window and you want to clear that window.
I don't know of any library methods for that, but you might just do:
well i am not doing any console i/o. Just simple one. i am trying to
clear the IDLE (one of python IDE distributed with the original
distribution) screen which is pretty easy but having to do
import cls
cls() everytime is boring (2 lines of boredom!!) so what i want is to be
able to do justcls()

and nothing more or even less!! ;-)

os.system("cls") #for windows
or
os.system("clear") #for unix yeah i have used the 'os' module's system() method but that wasn't what i meant.
Not the most advanced solution though.

;-) Thanx anyway mate.

[snip]
--
cheers,
Ishwor Gurung
Jul 18 '05 #3

P: n/a
On Sat, 2004-12-25 at 07:43, Ishwor wrote:
On 24 Dec 2004 15:33:26 -0800, Lars <la******@lycos.com> wrote:
Hi Iswor,

If I understand you correctly then your program is writing output to a
console/terminal window and you want to clear that window.
I don't know of any library methods for that, but you might just do:
well i am not doing any console i/o. Just simple one. i am trying to
clear the IDLE (one of python IDE distributed with the original
distribution) screen which is pretty easy but having to do

import cls
cls() everytime is boring (2 lines of boredom!!) so what i want is to be
able to do just cls()

and nothing more or even less!! ;-)


Assuming cls.cls() does the job for you, just add 'from cls import cls'
to your pythonrc ( ${HOME}/.pythonrc on UNIX , NFI on windows ).

On a side note, it'd be easier to read your post if you'd use the shift
key more often :-P

--
Craig Ringer

Jul 18 '05 #4

P: n/a
In the darkest hour on Sat, 25 Dec 2004 09:41:54 +1030,
Ishwor <is***********@gmail.com> screamed:
def cls():

for i in range(1,40):
print " ";


Slightly ot, but perhaps this'll work for you:

def cls():
print "\033[2J"
--
[ Artur M. Piwko : Pipen : AMP29-RIPE : RLU:100918 : From == Trap! : SIG:217B ]
[ 22:06:17 user up 10478 days, 10:01, 1 user, load average: 0.06, 0.06, 0.06 ]

Even God cannot change the past.
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.