DEV Community

perXautomatik
perXautomatik

Posted on

Answer: How to pipe input to python line by line from linux program?

Instead of using command line arguments I suggest reading from standard input (stdin). Python has a simple idiom for iterating over lines at stdin:

import sys
for line in sys.stdin:
    sys.stdout.write(line)

My usage example (with above's code saved to iterate-stdin.py):

$ echo -e "first line\nsecond line"

Top comments (0)