Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear Python Shell in IDLE [duplicate]

I'm running a script that uses a module that prints a lot of things on screen and I'm running out of RAM.
I can't make the module not to write anything for now.
The Python Shell stores absolutely everything and I want to clear it.
On similar questions the only answer I could find was to write os.system('cls') (on Windows), but it doesn't delete anything.
Is there a way to clear the Python Shell or to limit its size?
Thanks


Edit.
Well, this question was marked as duplicate and I am asked to clarify why it isn't.
I state that os.system('cls') doesn't work, while the answer to the question I supoosedly duplicate is to write os.system('cls').

like image 907
José Avatar asked Jul 03 '13 18:07

José


People also ask

How do you clear the shell in Python idle?

The commands used to clear the terminal or Python shell are cls and clear.

Can you clear the console in Python?

>>> cls = Cls() >>> cls # this will clear console.


2 Answers

By python shell, do you mean IDLE? Some quick googling suggests that IDLE doesn't have a clear screen even though lots of people seem to want one. If it's in a shell, then I'm surprised 'cls' isn't working.

If you like working in Idle, you might look at this for getting the functionality you want: http://idlex.sourceforge.net/extensions.html#ShellEnhancements The internet seems to think you should just stop using IDLE, however.

like image 112
Mongoose1021 Avatar answered Sep 21 '22 07:09

Mongoose1021


How are you running the script? Are you calling it from a shell? If so, you can redirect all output to a file like this:

python my_script.py > /out/to/some/path.log
like image 31
Jordan Avatar answered Sep 24 '22 07:09

Jordan