How to clear the interpreter console?

后端 未结 30 2197
自闭症患者
自闭症患者 2020-11-21 18:15

Like most Python developers, I typically keep a console window open with the Python interpreter running to test commands, dir() stuff, help() stuff

相关标签:
30条回答
  • 2020-11-21 18:25

    Quickest and easiest way without a doubt is Ctrl+L.

    This is the same for OS X on the terminal.

    0 讨论(0)
  • 2020-11-21 18:25

    I am using Spyder (Python 2.7) and to clean the interpreter console I use either

    %clear

    that forces the command line to go to the top and I will not see the previous old commands.

    or I click "option" on the Console environment and select "Restart kernel" that removes everything.

    0 讨论(0)
  • 2020-11-21 18:27

    OK, so this is a much less technical answer, but I'm using the Python plugin for Notepad++ and it turns out you can just clear the console manually by right-clicking on it and clicking "clear". Hope this helps someone out there!

    0 讨论(0)
  • 2020-11-21 18:28

    If you don't need to do it through code, just press CTRL+L

    0 讨论(0)
  • 2020-11-21 18:33

    Wiper is cool, good thing about it is I don't have to type '()' around it. Here is slight variation to it

    # wiper.py
    import os
    class Cls(object):
        def __repr__(self):
            os.system('cls')
            return ''
    

    The usage is quite simple:

    >>> cls = Cls()
    >>> cls # this will clear console.
    
    0 讨论(0)
  • 2020-11-21 18:33

    Arch Linux (tested in xfce4-terminal with Python 3):

    # Clear or wipe console (terminal):
    # Use: clear() or wipe()
    
    import os
    
    def clear():
        os.system('clear')
    
    def wipe():
        os.system("clear && printf '\e[3J'")
    

    ... added to ~/.pythonrc

    • clear() clears screen
    • wipe() wipes entire terminal buffer
    0 讨论(0)
提交回复
热议问题