An easy and fairly universal way to do this is to use the fileinput module.
import fileinput for line in fileinput.input()
This way you can use the script in the pipeline (as you need right now) or provide one or more files in the script as a parameter (think my_python_script.py input.txt input2.txt ).
source share