Clearing screen in Python

So I for a long time have used various means to clear the screen in Python. Several people on Replit have given me ways to make print clear the screen. But what I learned is that Replit has that built in. I have listed four different ways to use it below. Why has no one told me this before? Is it a lesser-known feature?

from replit import clear
from replit import *
import replit

These 4 are different ways to call clear() function from replit module, however they are not lesser known feature.

I personally think people giving solutions like print flushing or is.system(“clear”) but not replit.clear() is that they want to make codes able to be used easily without much pip package, which they are usable even without pips

Those are my opinions but I think it is because of this, what Im sure, however, is that replit.clear() is not lesser known


@QwertyQwerty54 This is not code help per say; I know what I’m doing. I just wanted to know why other people never mentioned this to me.

1 Like

Oh, I see. Just wasn’t sure if #general was the correct cat

It’s os not is btw

I prefer the ANSI code: print("\033c", end="")

1 Like

@InvisibleOne Interesting. The other solutions I’ve seen had flush=True in them as well as what you’ve put. I just run these ANSI print statements out of a Python library that I made (but bigminiboss got published for me). I tested it though and what you said works great. So why do some people add flush=True to their clear print statement?

flush forces the \033c to render immediately, so that other output at the time which may be important isn’t cleared. Only need it if you expect other output, e.g. from the debugger or a subprocess or thread, something you’d have in a discord bot or webserver

As UMAR said, flush forces the console to print the buffer. When printing stuff to the terminal, it will sometimes wait for a certain amount of characters to build up before printing them (simply put), flush will force it to print that buffer immediately.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.