How to clear the interpreter console?

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

    Here's a cross platform (Windows / Linux / Mac / Probably others that you can add in the if check) version snippet I made combining information found in this question:

    import os
    clear = lambda: os.system('cls' if os.name=='nt' else 'clear')
    clear()
    

    Same idea but with a spoon of syntactic sugar:

    import subprocess   
    clear = lambda: subprocess.call('cls||clear', shell=True)
    clear()
    

提交回复
热议问题