How to clear screen in Python interactive shell mode?

Discussion in 'Python' started by A. L., Sep 16, 2005.

  1. A. L.

    A. L. Guest

    In Python interactive mode, is there some function acting like 'clear'
    command in bash? Could somebody here give some advice?

    Thanks in advance.
    A. L., Sep 16, 2005
    #1
    1. Advertising

  2. A. L. wrote:

    >In Python interactive mode, is there some function acting like 'clear'
    >command in bash? Could somebody here give some advice?
    >
    >

    Under Linux/UNIX system (on x86 at least) you can use the CTRL+L
    combination to clear the screen.
    I do not now similar for Windows and MACs.

    Les
    Laszlo Zsolt Nagy, Sep 16, 2005
    #2
    1. Advertising

  3. A. L.

    A. L. Guest

    Thank you very much. I have tested it under Cygwin, and that works. But
    it fails under Windows Python Shell Mode.
    A. L., Sep 16, 2005
    #3
  4. On Thu, 15 Sep 2005 21:18:33 -0700, A. L. wrote:

    > In Python interactive mode, is there some function acting like 'clear'
    > command in bash? Could somebody here give some advice?
    >
    > Thanks in advance.



    Something like this may help:

    def clearscreen(numlines=100):
    """Clear the console.

    numlines is an optional argument used only as a fall-back.
    """
    import os
    if os.name == "posix":
    # Unix/Linux/MacOS/BSD/etc
    os.system('clear')
    elif os.name in ("nt", "dos", "ce"):
    # DOS/Windows
    os.system('CLS')
    else:
    # Fallback for other operating systems.
    print '\n' * numlines


    --
    Steven.
    Steven D'Aprano, Sep 16, 2005
    #4
  5. A. L.

    A. L. Guest

    I have tested it under windows python console, and it works.

    Thank you very much.
    A. L., Sep 16, 2005
    #5
  6. A. L.

    bruce Guest

    elif os.name in ("nt", "dos", "ce"):
    # emacs/Windows
    What`s the right statement here?
    bruce, Sep 16, 2005
    #6
    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. Replies:
    2
    Views:
    885
    Micah Elliott
    Nov 16, 2005
  2. Shawn Minisall

    clear shell screen

    Shawn Minisall, Oct 29, 2007, in forum: Python
    Replies:
    1
    Views:
    642
    Tim Roberts
    Oct 31, 2007
  3. Gabriel Genellina

    Re: clear shell screen

    Gabriel Genellina, Oct 29, 2007, in forum: Python
    Replies:
    0
    Views:
    492
    Gabriel Genellina
    Oct 29, 2007
  4. Shawn Minisall

    Re: clear shell screen

    Shawn Minisall, Oct 29, 2007, in forum: Python
    Replies:
    1
    Views:
    559
    Dennis Lee Bieber
    Oct 30, 2007
  5. Gabriel Genellina

    Re: clear shell screen

    Gabriel Genellina, Oct 29, 2007, in forum: Python
    Replies:
    0
    Views:
    485
    Gabriel Genellina
    Oct 29, 2007
Loading...

Share This Page