How to clear the interpreter console?

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

    This should be cross platform, and also uses the preferred subprocess.call instead of os.system as per the os.system docs. Should work in Python >= 2.4.

    import subprocess
    import os
    
    if os.name == 'nt':
        def clearscreen():
            subprocess.call("cls", shell=True)
            return
    else:
        def clearscreen():
            subprocess.call("clear", shell=True)
            return
    

提交回复
热议问题