Clearing the screen

Discussion in 'Python' started by Ishwor, Dec 24, 2004.

  1. Ishwor

    Ishwor Guest

    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
    Ishwor, Dec 24, 2004
    #1
    1. Advertising

  2. Ishwor

    Lars Guest

    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
    Lars, Dec 24, 2004
    #2
    1. Advertising

  3. Ishwor

    Ishwor Guest

    On 24 Dec 2004 15:33:26 -0800, Lars <> 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!! ;-)

    >
    > 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
    Ishwor, Dec 24, 2004
    #3
  4. Ishwor

    Craig Ringer Guest

    On Sat, 2004-12-25 at 07:43, Ishwor wrote:
    > On 24 Dec 2004 15:33:26 -0800, Lars <> 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
    Craig Ringer, Dec 25, 2004
    #4
  5. In the darkest hour on Sat, 25 Dec 2004 09:41:54 +1030,
    Ishwor <> 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.
    Artur M. Piwko, Jan 1, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Hemmings

    Clearing the output screen

    Colin Hemmings, Feb 20, 2006, in forum: Java
    Replies:
    3
    Views:
    9,778
    ~Glynne
    Feb 21, 2006
  2. Sebastian Becker

    Clearing Screen

    Sebastian Becker, Jan 12, 2005, in forum: C++
    Replies:
    2
    Views:
    490
    Mike Wahler
    Jan 12, 2005
  3. Miki Tebeka

    Clearing IDLE's screen?

    Miki Tebeka, Feb 8, 2004, in forum: Python
    Replies:
    3
    Views:
    750
    Scott David Daniels
    Feb 9, 2004
  4. Nick Coghlan

    Re: Clearing the screen

    Nick Coghlan, Dec 25, 2004, in forum: Python
    Replies:
    5
    Views:
    2,833
    Steve Holden
    Dec 27, 2004
  5. Kaizer
    Replies:
    3
    Views:
    257
    Kaizer
    Dec 10, 2005
Loading...

Share This Page