Why Pycharm returns an up arrow instead of cleaning screen?

Viewed 607

I use PyCharm as my IDE. I use console in PyCharm and I want to clean screen by:

>>>2+2
4
>>>print("example")
example
>>>from os import system
>>>system("cls")
0

Before 0 I see an arrow, but console isn't cleared. Same situation with the scripts. It works on basic python shell.

1 Answers

PyCharm has two different consoles.

The Terminal that runs Command prompt in Windows and Python Console that runs project interpreter with helper script C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pydev\pydevconsole.py.

Terminal

To clear terminal console press Ctrl+K.

When you run:

from os import system
system('cls')

you get exit code from system command and 0 means success.
You can assign it to tmp variable _ = system('cls') to get rid of it. But keyboard shortcut is much faster.

Python Console

When you try to run cls command you get this:

Python Console

That bold up-arrow is just a glyph that represents FORM FEED (ASCII value 12 or 0x0C - showed by next print statement). Helper script intercepts output and displays it instead of clearing console.

To clear python console you have to right click on text and choose Clear All.
This command doesn't have a shortcut, you can assign one in File > Settings... > Keymap > Other > Clear All.

Related