[Tutor] how to get variable from an external script or program

Alan Gauld alan.gauld at btinternet.com
Sat May 30 00:09:35 CEST 2009


"vince spicer" <vinces1979 at gmail.com> wrote 

> import commands
> output = commands.getout("ls -lah")

There are many ways to do this in Python including 
os.popen, commands and subprocess.

But subprocess is the "officially correct" version, the others 
are deprecated and could theoretically disappear in a future 
version of Python. (But not soon I suspect because of the 
amount of legacy code that uses it!)

But its definitely worth weaning oneself onto subprocess 
even though it is initially harder work. In the end the superior 
flexibility and consistency of approach pay back.

Alan G.




More information about the Tutor mailing list