How to clear the interpreter console?

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

    my way of doing this is to write a function like so:

    import os
    import subprocess
    
    def clear():
        if os.name in ('nt','dos'):
            subprocess.call("cls")
        elif os.name in ('linux','osx','posix'):
            subprocess.call("clear")
        else:
            print("\n") * 120
    

    then call clear() to clear the screen. this works on windows, osx, linux, bsd... all OSes.

提交回复
热议问题