[Tutor] Clearing the Console Screen
Kent Johnson
kent37 at tds.net
Thu Jun 16 18:24:32 CEST 2005
Don Parris wrote:
> Thanks! I thought there had to be a way to call the OS' clear screen
> command, but was going about it the wrong way. I was trying to use
> sys.clear instead of os.system. Would it be difficult to test the OS,
> store the result in a variable, and call the comand based on the variable
> result? Or would it be simpler to have users edit the script for their OS?
You could try this (from http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/3edf6589c533f78e):
import os
if os.name == "nt":
os.system("cls") # Works in w2k
else:
os.system("clear") # Works in cygwin's Bash
> Mind you, there may be other areas where I need an OS-specific command. I'm
> beginning to get an idea of the challenges of portability though. ;)
Python actually gets a lot of this right, you may find it's easier than you think to write portable Python.
Kent
More information about the Tutor
mailing list