Skip to content
← Back to Community
How to clear the console in python
Profile icon
ThatOneGuy1234

I'm trying to make a console based game in python, but I want to clear the text that has accumulated in the console. Is there a certain command for this or will I just have to live with it?

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
Timgb11
Profile icon
ThatOneGuy1234
Comments
hotnewtop
Profile icon
Coder100

Sure

import os os.system("clear")

easy, right?

Profile icon
ThatOneGuy1234

@Coder100 Thanks!

Profile icon
Coder100
Profile icon
JonahElias

@Coder100 I tried this in PyCharm and it said
TERM environment variable not set.

Profile icon
Coder100

@JonahElias then set the TERM env variable?

Profile icon
Coder100

technically it should work no matter what, in the backend, in C:

int main() { system("clear"); }

which works on all windows and linux
@JonahElias

Profile icon
JonahElias

@Coder100 but what does that mean?

Profile icon
Coder100

wdym what does it mean, ig your environment is just weird @JonahElias

Profile icon
JonahElias

@Coder100 okay thanks

Profile icon
GulliverM

obtw os.system() is used for running bash