subprocess.Popen - file like object from stdout=PIPE

Chris Rebert clp2 at rebertia.com
Wed Feb 4 04:43:37 EST 2009


On Wed, Feb 4, 2009 at 1:22 AM, Helmut Jarausch <jarausch at skynet.be> wrote:
> Hi,
>
> using e.g.
> import subprocess
> Package='app-arch/lzma-utils'
> EQ=subprocess.Popen(['/usr/bin/equery','depends',Package],stdout=subprocess.PIPE)
> EQ_output= EQ.communicate()[0]
>
> EQ_output is a string containing multiple lines.
>
> I'd prefer a file-like object, e.g. EQ_OUT
> so that I can loop over the lines of it like
>
> for line in EQ_OUT :
>  ...

Is there some reason that:

for line in EQ_OUT.splitlines():
    #...

Does not meet your needs?

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list