Snippet: The leanest Popen wrapper

Terry Reedy tjreedy at
Wed Aug 3 22:20:22 CEST 2011

On 8/3/2011 11:29 AM, Phlip wrote:

> This is either a code snippet, if you like it, or a request for a
> critique, if you don't.

A learning exercise but pretty useless otherwise. As others pointed out, 
immediately stripping off \n is a bug relative to *your* function 
description. Also, you yourself then give an example of joining with \n. 
But that does not restore the final \n. The rest duplicates the 
iteration ability of the .stdout file object.

For repeated execution of code like
you can once create a 'packetized' bound method object like so
   cmdline = process.stdout.readline
and then, without repeating the attribute lookups, repeatedly call

Terry Jan Reedy

More information about the Python-list mailing list