How to clear screen in Python interactive shell mode?

Steven D'Aprano steve at
Fri Sep 16 13:03:48 CEST 2005

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 == "posix":
        # Unix/Linux/MacOS/BSD/etc
    elif in ("nt", "dos", "ce"):
        # DOS/Windows
        # Fallback for other operating systems.
        print '\n' * numlines


More information about the Python-list mailing list