D
D
Daniil Kalinin2020-05-07 18:16:57
Python
Daniil Kalinin, 2020-05-07 18:16:57

How to clear python console?

I am writing a simple reinforcement learning algorithm, which has a simple animation, through console output. So, to show a new animation frame, I need to clear this console somehow. Right now I'm using print(100*'\n') but it doesn't look very pretty due to console scrolling. I'm using PyCharm IDE if that matters. Tried os.system('cls') and print('\k') - doesn't work. Is it possible to somehow clear the console in order to re-output a new animation frame into it?

PS It is worth adding: the frame is a square matrix of size n, each element of which is a separate symbol: =, if the cell is empty, A - if there is an agent in the cell, E - if there is an enemy in the cell. The matrix is ​​updated and a new frame is displayed. Now n=7. The total number of frames cannot be known in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-05-07
@DKay7

This is how it works on Linux:

import os

print('Hello')
input()
os.system('cls||clear')
print("Привет")
input()

You probably have windows. And you need to try in the OS console, not in the PyCharm console. After all, it would be strange if you had to install a development environment to run a program (or game)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question