Python universal CLS?

Started by
2 comments, last by Zahlman 15 years, 3 months ago
I'm trying to find a way to make a quick clear screen command that works on all computers. I've looked around and can't find one...mainly people just saying that you have to know the system to know which one works... and then you can find the system, but then i don't know which cls works with which system and have no way of testing so is there a universal CLS out there for Python?
Advertisement
The most portable method to clear a console window is to write a number of blank lines (i.e. newline characters), some number greater than 20 in general. However, remember that some users may have extremely large terminals, and stdout need not actually be connected to a terminal (it could be a file).

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

If you want to have that kind of control over your console window, you may want to look into libraries such as ncurses.
Create-ivity - a game development blog Mouseover for more information.
Quote:Original post by Durakken
I'm trying to find a way to make a quick clear screen command that works on all computers.


Sorry. Not possible. In any programming language.

Not all computers have a "screen", let alone a clearable one. Of course, by "screen" it appears that you really mean "console window". Python's output isn't even necessarily sent to a console window. Try using IDLE (the IDE that comes with Python) to run your program; now ask what the "clear screen" command ought to do there. Or try something like 'myfile.py > output.txt' from the command line; notice how nothing gets printed to "the screen" at all, but is instead dumped into the named text file.

If you are looking for the amount of control over "how the output looks" that "ability to clear the screen" implies, then you don't really want to just 'print' your output and will have to use something more sophisticated. Note that using more sophisticated tools effectively will require new code design skills that you probably haven't yet had a chance to practice.

This topic is closed to new replies.

Advertisement