Inside the Python script you should be reading from sys.stdin:
import sys
INPUT = sys.stdin
def do_something_with_data(line):
# Do your magic here
...
return result
def main():
for line in INPUT:
print 'Result:', do_something_with_data(line)
if __name__ == '__main__':
main()
Inside the iterative interpreter you can use the subprocess module mock sys.stdin.
In[0]: from test.py import *
In[1]: INPUT = subprocess.Popen(['grep', 'ABC', 'input.txt'], \
stdout=subprocess.PIPE).stdout
In[2]: main()
You can also pipe the output to a file and just read from the file. For practical purposes stdin is just another file.
In[0]: ! grep "ABC" input.txt > output.txt
In[1]: INPUT = open('output.txt')
In[2]: main()