How to clear screen in python

Started by
4 comments, last by alvaro 10 years ago

OKay, so i've been learning python for the last month and three weeks using the python IDLE, but it's become really annoying to see the games i make stack up all the text on top of each other. Is there any way that i can make it so that the screen is cleared and the game is updated and re-shown to the player? thanks.

Advertisement

Try this:


import os
os.system('cls')

on windows or this on linux:


os.system('clear')

Good Luck!

Another option is to say something like this:


print '\n' * 100

Thank you weberM that worked perfectly, and Oralordos XD lmaoo yea i guess that could work too, but then you'd have a scrolling bar on the side which i wouldn't want there

To make your code more cross platform you can use sys.platform to find out what os you are running on.

If your terminal supports ANSI escape codes, you can do this:

sys.stdout.write("\033[2J")

This topic is closed to new replies.

Advertisement