python – How to clear the interpreter console?

python – How to clear the interpreter console?

As you mentioned, you can do a system call:

For Windows:

>>> import os
>>> clear = lambda: os.system(cls)
>>> clear()

For Linux it would be:

>>> import os
>>> clear = lambda: os.system(clear)
>>> clear()

here something handy that is a little more cross-platform

import os

def cls():
    os.system(cls if os.name==nt else clear)

# now, to clear the screen
cls()

python – How to clear the interpreter console?

Well, heres a quick hack:

>>> clear = n * 100
>>> print clear
>>> ...do some other stuff...
>>> print clear

Or to save some typing, put this file in your python search path:

# wiper.py
class Wipe(object):
    def __repr__(self):
        return n*1000

wipe = Wipe()

Then you can do this from the interpreter all you like 🙂

>>> from wiper import wipe
>>> wipe
>>> wipe
>>> wipe

Leave a Reply

Your email address will not be published.