[Tutor] Question about parameters of sys module
Terry Carroll
carroll at tjc.com
Fri Jan 16 16:17:15 EST 2004
On Fri, 16 Jan 2004, JD wrote:
> ...I found a line that I couldn't understand....
>
> os.system('clear')
>
> I know what it does: it clears the screen. What made me
> uncertain is that the "clear" value is not documented in
> the sys module documentation.
>
> As it is not a variable defined in the script, I suppose it
> is the parameter of a fonction of the sys module. Where may
> I find more information about it? And chat exactly is this
> 'clear'? A variable?
'clear' is a literal. os.system() simply takes as its argument a command
line to be executed by the operating system. On your operating system,
there is a command called "clear" that clears the screen.
If you were to replace it with, for example:
os.system('dir')
the OS would execute the 'dir' command, and you'd see a directory listing.
This isn't limited to simple output commands, by the way. If you gave it
os.system('delete filename'), it would execute that, deleting the file
named "filename". So be careful with os.system().
Neither Python nor the os.system() method knows what the string it's
passed actually means. In this case, neither Python nor os.system gives
any importance to the string "clear"; it just passes it to the OS for
execution. That's why you don't see "clear" documented in any of your
Python docs.
--
Terry Carroll
Santa Clara, CA
carroll at tjc.com
Modell delendus est
More information about the Tutor
mailing list