0

I know these are questions: this and this and this. I have tried all of these methods in pycharm, but they either a) not work or b) I get a weird character on my screen, that looks like a 0 with diagonal line going through it. I can't copy it for some reason, so I can't show you.

For instance this:

import os
from time import sleep
print("lots of text")
sleep(5)
os.system('cls')

What should happen in the above is tht the message should be displayed for 5 seconds then disappear, but all I get is that weird character... In contrast when I ran my python program from command line, it worked as expected i.e. the screen cleared. I am very confused.

So my questions are:

Why don't any of them work in pycharm?

What does work in pycharm?

khelwood
  • 55,782
  • 14
  • 81
  • 108
fartgeek
  • 178
  • 3
  • 12

4 Answers4

1

I don't know in which version of PyCharm this was introduced. I guess it must have been after this question was asked.

The way to clear the PyCharm Python Console is by using the context menu. Right mouse click in the upper part of the console (where the lines with >>> prompts are closer together) and select Clear All.
Alse see this PyCharm Support Community article.

enter image description here

Incidentally, none of the questions linked to in the OP's original post relate to PyCharm and do not answer the OP's question.

Bumpyride
  • 51
  • 2
  • This is the solution, the other answers are useless. Thanks so much for your help! It allows me to print out just the console output that I want to a PDF without closing and reopening the console. Works in DataSpell as well. – Nicholas Stommel Apr 10 '23 at 15:45
1

Ok, so, I have been having this problem as well — after scouring the internet, the os commands work BUT you need to enable the terminal emulator.

In the PyCharm toolbar, click Run, Edit Configurations, and the toggle for "Emulate Terminal in Output Console" should be under Execution in the pop up. Emulate Terminal toggle

I had to get help from the PyCharm team on this one, so here's to them responding at lightning speed.

0

Answer
The cls command doesn't work on a standard pycharm project because it is an IDE and certain os commands don't work in the same way it would with the windows command line.

There is currently no way to clear the console output in PyCharm, other than to manually do it by using the cls command through the terminal in PyCharm or through a keyboard shortcut set through the pycharm preferences menu. You can try to emulate a keyboard shortcut, but this would be difficult, and unless you absolutely need it, I would not recommend clearing the terminal output after a program is run.

References and Additional Links
https://teamtreehouse.com/community/clear-screen-for-pycharm-as-if-it-were-on-console-or-cmd

DapperDuck
  • 2,728
  • 1
  • 9
  • 21
0

cls only temporarily clears it. Next command brings back all previous messages. The best option is to right click on the Terminal and choose Clear Buffer enter image description here

Blue Clouds
  • 7,295
  • 4
  • 71
  • 112