A python function similar to clear() from replit

Viewed 643

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 Answers

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')
Related