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

Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120
José
  • 1,582
  • 5
  • 15
  • 22
  • 1
    What exactly do you mean by "Python Shell", python command line? chrome extension? idle shell? some other IDE shell? – Dima Tisnek Jul 03 '13 at 18:07
  • I was talking about the window called 'Python Shell' that opens with the icon called 'IDLE (Python GUI)' (on MS Windows). – José Jul 12 '13 at 14:52

3 Answers3

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.

Mongoose1021
  • 268
  • 1
  • 6
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
Jordan
  • 31,971
  • 6
  • 56
  • 67
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.
nmichaels
  • 49,466
  • 12
  • 107
  • 135