How to clear the interpreter console?

后端 未结 30 2696
自闭症患者
自闭症患者 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: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

提交回复
热议问题