The answer to this question is no , you can not cancel the interactive shell or IDLE content with a Python command like you can in Bash with command clear . There are, however, at least 2 alternative solutions:
Use a loop that iterates for a tot of times (eg 100) by making a print of an empty line, thus simulating that IDLE is being cleaned. The following may be an example of the simple code:
def clear(times=100):
"""simulates the cleanning of the IDLE"""
if isinstance(times, int):
for i in range(times):
print()
The problem with this solution is that the call to print()
requires a lot of resources, and it takes a lot of time to clean the screen, and I do not think it's a great solution.
Clear the program from the terminal , thus taking advantage of the Bash clear command. In this case, the program works much more smoothly, but always depends on a terminal.
If you know other solutions, do not hesitate to propose;)