Python Forum
how to clear the console when the programm is running (not manually) - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: how to clear the console when the programm is running (not manually) (/thread-4681.html)



how to clear the console when the programm is running (not manually) - hello_its_me - Sep-02-2017

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


RE: how to clear the console when the programm is running (not manually) - Larz60+ - Sep-02-2017

more info please.
A bit of code would help with specifics on where in the code you feel it is going wrong.


RE: how to clear the console when the programm is running (not manually) - sparkz_alot - Sep-02-2017

This has always worked for me (though have not tried an Mac)

import os

os.system('cls' if os.name == 'nt' else 'clear')



RE: how to clear the console when the programm is running (not manually) - nilamo - Sep-29-2017

If you don't like using os.system...
[print() for _ in range(80)]



RE: how to clear the console when the programm is running (not manually) - gruntfutuk - Sep-30-2017

print('\n'*80)



RE: how to clear the console when the programm is running (not manually) - wavic - Sep-30-2017

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