Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 992
Sasquatch Avatar asked Mar 05 '26 10:03

Sasquatch


1 Answers

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()
like image 62
sancho.s ReinstateMonicaCellio Avatar answered Mar 07 '26 22:03

sancho.s ReinstateMonicaCellio