About Reading Pipe Output from a Shell Command

You can read the pipe output of a shell command line by line using sys.stdin:

import sys

for line in sys.stdin.read().splitlines():
    print(line)

Tips and Tricks Programming Python 3