0

I want to know how to clear the console window that works on ALL platforms (Windows, Mac, Every single Linux/Unix distribution) and does not use the os.system() method or subprocess.Popen() method (or any other system call method)

Also, please don't make me use something like print("\n" * 2000, end="", flush=True) or

for integer in range(1, 2001):
    print("\n", end="", flush=True)

[Linux/Unix(Debian/Ubuntu), Python 3.8.10]

  • look at this: [Python Clear Console Across All OSes](https://stackoverflow.com/questions/70384028/python-clear-console-across-all-oses/70384054#70384054) – ma4strong Dec 28 '21 at 13:11
  • on Linux (and probably on Mac) you can use special codes in `print()` to clear console/terminal - but not all console/terminal may have this function. I don't use Windows but probably the only method is to run `cls` which needs `os.system()` or `subprocess`. Frankly, I don't like when program clearn screen because I can't see previous values. If you want to create `TUI` (`Text User Interface`) then maybe see modules like `curses` or [rich](https://github.com/willmcgugan/rich), [textual](https://github.com/willmcgugan/textual) – furas Dec 28 '21 at 18:26
  • @furas On Windows 10, i tried using the ```click``` module. ```click.clear()``` –  Dec 29 '21 at 01:25
  • see source code for [click.clear()](https://github.com/pallets/click/blob/main/src/click/termui.py#L436) - it uses `os.system("cls")` on Windows. It also shows how to use special codes with `print()` or `sys.write()` on other systems. – furas Dec 29 '21 at 13:11

0 Answers0