Clear the terminal window.

Gribouillis 0 Tallied Votes 273 Views Share

Printing a convenient ansi escape sequence clears the terminal (if you're running python from a terminal). Similar techniques could be used to print in colors.

def clear():
  print("\x1B[2J")

clear()
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Linux only?

Gribouillis 1,391 Programming Explorer Team Colleague

No, with ANSI.SYS, it should work on windows too.

Gribouillis 1,391 Programming Explorer Team Colleague

Correction: you were right, I couldn't make it work on windows. The ANSI.SYS driver works only with very old versions of windows. You would need a terminal emulator similar to the linux console. There is a module console for windows, with slightly different control sequences. See if it works with your versions of windows/python.

So let's say it's linux only...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.