Python Forum

Full Version: how to clear the console when the programm is running (not manually)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
HI,

I am used to C# and there is the option "Console.Clear()"to clear the console but I found no way that worked for me. The most used way I found was "import os" but that didn't work at all is there anything else I could try?

Thanks
more info please.
A bit of code would help with specifics on where in the code you feel it is going wrong.
This has always worked for me (though have not tried an Mac)

import os

os.system('cls' if os.name == 'nt' else 'clear')
If you don't like using os.system...
[print() for _ in range(80)]
print('\n'*80)
This will position the cursor at the botom of the terminal window. 
Better use suprocess module
import subprocess

try:
    subprocess.call(['cls']) # Windows call
except FileNotFoundError:
    subprocess.call(['clear']) # *nix call