I usually do this in Perl:
whatever.pl
while(<>) { #do whatever; }
then cat foo.txt | whatever.pl
cat foo.txt | whatever.pl
Now, I
import sys for line in sys.stdin: # do stuff w/line