Search code examples
pythonpython-idle

I want to clear the previous code in python


So I have this code and immediately after the code is completed I want to clear the screen and run another code automatically, please how do I do this?

def load():
    n("Loading")
    for load in range(1,4):
        n(".")
        time.sleep(1)


load()

Solution

  • To clear the output of the script use following on Windows:

    import os
    os.system('cls')
    

    Or this for Linux/MacOS

    import os
    os.system('clear')