Sasquatch
Sasquatch

Reputation: 45

Clear python console

I am trying to make a program, therefore I need to clean my console to make it better for my eyes. I used this code in python:

class Screen:
    @staticmethod
    def clear():
        os.system('cls' if os.name == 'nt' else 'clear')

I tried it on my pc with pycharm in terminal mode. It didn't work. A friend of my tried it to with exactly the same one and there it worked. We have the same windows versions, the same pycharm versions and also the same python versions.

Thanks for any help!

Upvotes: 3

Views: 247

Answers (2)

I tried code below, under Msys2 portable in Win 10, and it worked. I am not sure it works in Pycharm, and I am not sure you need this as mandatory.

#!/usr/bin/env python

class Screen:
    @staticmethod
    def clear():
        import os
        os.system('cls' if os.name == 'nt' else 'clear')

def main():
    sc = Screen()
    sc.clear()
    return

if (__name__ == '__main__' ) :
    main()

Upvotes: 1

Mies van der Lippe
Mies van der Lippe

Reputation: 702

The terminal built in to PyCharm doesn't support clear/cls. You can emulate it's behavior by just using print("\n" * 80). Some shells do it this way too.

Upvotes: 0

Related Questions