command substitution

Joonas Paalasmaa joonas at olen.to
Mon Jul 16 07:01:40 EDT 2001


Joonas Paalasmaa wrote:
> 
> Raphael Bauduin wrote:
> >
> > Hi!
> >
> > I was looking for a solution like in bash, which let you put the standard
> > output of a command in a variable(in bash, you can do it like OUT=`ls` or
> > OUT=$(ls) ).
> >
> > If you have another way to take the standard output of a command and put it
> > in a variable, it would be helpfull too.
> 
> out = popen("ls", "r").read()
> 
> And if you want a list of files.
> out = popen("ls", "r").readlines()
Oops!
This may work better.

import os
out = os.popen("ls", "r").read()



More information about the Python-list mailing list