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. Advertisements

  2. 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. Advertisements

  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. 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 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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.