How to clear the interpreter console?

How to clear the interpreter console?

Asked on November 10, 2018 in Python.
Add Comment


  • 3 Answer(s)

    For Windows

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

    For Linux the lambda becomes

    >>> clear = lambda: os.system('clear')
    
    Answered on November 10, 2018.
    Add Comment

    Here is the simple method, check this out:

    import os
     
    def cls():
        os.system('cls' if os.name=='nt' else 'clear')
     
    # now, to clear the screen
    cls()
    

     

    Answered on November 10, 2018.
    Add Comment

    Here is the simple method:

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

    Add this file in your python search path for saving some typing:

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

    Now the interpreter can be done as user like:

    >>> from wiper import wipe
    >>> wipe
    >>> wipe
    >>> wipe
    
    Answered on November 10, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.