6

I'm using Eclipse for writing Python, and I want to be able to easily clear the screen. I've seen this question, and tried (among other things suggested there) the following solution

import os

def clear():
    os.system('cls' if os.name == 'nt' else 'clear')

but it doesn't entirely solve my problem. Instead of clearing the screen, the routine prints a small square (as if wanting to print an unknown character) to the command output window in Eclipse.

Typing cls in the command line works perfectly fine, as does running a Python script with the above code from command line. But how can I make it look nice in Eclipse as well?

braX
  • 11,506
  • 5
  • 20
  • 33
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
  • did you try '`clear`' instead of '`cls`' within the Eclipse console? (just to check) – VonC Mar 18 '10 at 05:10
  • I did - since this line of code runs an os command, I get the same error message I would if I'd type 'cls' it in command prompt: "'cls' is not a known command..." – Tomas Aschan Mar 18 '10 at 06:05

3 Answers3

2

The problem with running it in eclipse is that cls uses ANSI escape sequences to clear the screen. What I mean by this is that to clear the screen, cls writes a string such as "\033[[80;j" to the output buffer. The native console (the one outside of eclipse) interprets this as a command to clear the screen, but the eclipse console doesn't understand it, so just prints a small square as if printing an unknown character.

Joe D
  • 2,855
  • 2
  • 31
  • 25
0

Clearing in outputs is actually not possible. The best hack is to print full of line breaks. IDEs like Eclipse never simulate terminals properly.

Ming-Tang
  • 17,410
  • 8
  • 38
  • 76
0

As its just eclipse problem I suppose it will not affect your final product if you want to clean your final users' screen while for eclipse environment there is a little button in top-right of the console screen which enables you from cleaning it.

Polla A. Fattah
  • 801
  • 2
  • 11
  • 32