[Tutor] Question about parameters of sys module

Alan Gauld alan.gauld at blueyonder.co.uk
Sat Jan 17 03:17:09 EST 2004


>> Python nor os.system gives any importance to the string
>> "clear"; it just passes it to the OS for execution.
>
> But as far as I know, this type of commands can be produced 
> independently from the OS with the sys module and his 
> functions. In which cas would you use the os.sys() method?

The os module contains common OS commands that you can 
call from within Python. This is usually more efficient 
than calling os.system() because os.system() starts up 
another process. But not all OS commands are available 
in the os module and for anything else you need to use 
os.system() - or os.popen() etc.

> To make my question simple: is there a rule to determine 
> the use of either os.system() or sys module?

The sys module contains things about the Python system. 
It does not generally contain anything to do with the OS,
that is held in the os module. 

The general rule for use of the os module is that if the 
command exists in os then use it from their, if it doesn't 
and you don't need to capture the output use os.system. 
If os does not have the command and you need to capture 
the output use os.popen()

HTH

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld







More information about the Tutor mailing list