How to clear Python Shell in IDLE [duplicate]
Asked Answered
S

3

5

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').

Snelling answered 3/7, 2013 at 18:0 Comment(2)
What exactly do you mean by "Python Shell", python command line? chrome extension? idle shell? some other IDE shell?Divert
I was talking about the window called 'Python Shell' that opens with the icon called 'IDLE (Python GUI)' (on MS Windows).Clarhe
Q
4

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.

Quinquennial answered 3/7, 2013 at 18:7 Comment(5)
Question is about freeing up memory, not about clearing screen.Kronos
It's about both. The window get so big I suspect it's one of the culprits.Clarhe
Yes, I mean IDLE. Thanks.Clarhe
@Snelling clearing screen is not related to RAM, if you've created some large lists in memory then clearing screen won't free any memory.Kronos
+1, don't use IDLE. ipython for quick stuff, pycharm as fat ide.Divert
C
2

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
Case answered 3/7, 2013 at 18:2 Comment(1)
Or /dev/null if you don't care about the output.Mills
M
2

If the module is just printing, you can use this:

import sys
sys.stdout = open('/dev/null', 'a') # or a real file, if you care about output.
Mills answered 3/7, 2013 at 18:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.