Python Forum
how to clear the console when the programm is running (not manually)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to clear the console when the programm is running (not manually)
#1
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
Reply
#2
more info please.
A bit of code would help with specifics on where in the code you feel it is going wrong.
Reply
#3
This has always worked for me (though have not tried an Mac)

import os

os.system('cls' if os.name == 'nt' else 'clear')
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#4
If you don't like using os.system...
[print() for _ in range(80)]
Reply
#5
print('\n'*80)
I am trying to help you, really, even if it doesn't always seem that way
Reply
#6
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  manually input data jpatierno 0 315 Nov-10-2023, 02:32 AM
Last Post: jpatierno
  embed python script in C programm gucio321 0 580 Feb-11-2023, 10:47 AM
Last Post: gucio321
  User serial/pyserial to send messages to an arudino via terminal manually bkapadia 2 2,659 Mar-10-2021, 11:26 AM
Last Post: Larz60+
  to call via console a python-programm Liki 9 3,135 Nov-22-2020, 01:10 AM
Last Post: bowlofred
  Problem running script within console koepjo 3 9,801 Mar-26-2020, 07:11 AM
Last Post: koepjo
  Manually create a hex value Stas43 5 2,965 Feb-27-2020, 08:28 AM
Last Post: Stas43
  How to manually define color bar scale in seaborn heatmap SriRajesh 3 18,171 Sep-08-2019, 11:12 AM
Last Post: RudraMohan
  Keypress when running a python app in a console on windows Stephen 6 8,875 Apr-16-2019, 12:38 PM
Last Post: Stephen
  keep running Console Application MrJoo 3 3,019 Dec-25-2018, 08:59 PM
Last Post: metulburr
  How to clear IPython console in Spyder? Vai 7 55,655 Aug-20-2018, 09:43 PM
Last Post: james_balcomb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020