Clear command line output from Python [Eclipse]

11,418

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.

Share:
11,418
Tomas Aschan
Author by

Tomas Aschan

I am an engineering physicist from Stockholm, Sweden, with a passionate interest in programming and software architecture. Since creating my first program at age 12 (a VB6 app that showed a smiley when a button was clicked) I've spent many hours in front of my computer, watching screen casts and reading blogs about programming as well as trying all the new concepts out in my own programs. With a Master's degree in Engineering Physics from the Royal Institute of Technology in Stockholm, Sweden, I have deepened my modelling and reasoning skills, as well as had the opportunity to try out many different technologies and tools. I am currently working as a software engineer at Spotify, mostly massaging data to enable our internal research into developer productivity.

Updated on June 17, 2022

Comments

  • Tomas Aschan
    Tomas Aschan about 2 years

    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?