1

I'm looking for a function that works exactly like replit.clear() for windows. Because the tutorial I follow is taught through replit but I'm using pycharm. I tried installing replit package through pycharm , install was successfull. But still when I run the function with replit. clear() after importing replit, there is no difference in output, it's as if I commented that particular line having replit.clear(). I tried using os module too

import os
print("before clear")
os.system("clear")
print("after clear")

but i get

'clear' is not recognized as an internal or external command,
operable program or batch file.

when i tried running this code,

import os
print("before clear")
os.system("cls")
print("after clear")

I get these(which is not desirable), here "before clear" should vanish

before clear
after clear

1 Answers1

1

You can do it using os.system(). However there are different arguments based on your OS:

If you're using Linux or Mac:

import os
os.system(‘clear’)

If you're using Windows:

import os
os.system('cls')
Shivam Roy
  • 1,961
  • 3
  • 10
  • 23
  • I tried but I get ``` 'clear' is not recognized as an internal or external command, operable program or batch file. ``` – Gnaneshwaar May 13 '21 at 09:42
  • But still, I'm facing a problem. I've run the latest edit of yours. I updated the question accordingly. – Gnaneshwaar May 13 '21 at 12:34
  • The problem is actually with using Pycharm , this would work if you were running the code in Terminal or some other IDE (can't comment for all IDE's). If you're okay with using keyboard shortcuts then you can check this thread: https://stackoverflow.com/questions/27241268/clear-pycharm-run-window – Shivam Roy May 13 '21 at 14:45
  • 1
    Please consider upvoting and accepting answers if you found it helpful, keeping up with the Stack Overflow culture, thanks :) – Shivam Roy May 16 '21 at 14:53