stdin

How do I iterate over all lines of files passed on the command line?

How do I iterate over all lines of files passed on the command line? Question: I usually do this in Perl: whatever.pl while(<>) { #do whatever; } then cat foo.txt | whatever.pl Now, I want to do this in Python. I tried sys.stdin but I have no idea how to do as I have done …

Total answers: 6

How do I pass a string into subprocess.Popen (using the stdin argument)?

How do I pass a string into subprocess.Popen (using the stdin argument)? Question: If I do the following: import subprocess from cStringIO import StringIO subprocess.Popen([‘grep’,’f’],stdout=subprocess.PIPE,stdin=StringIO(‘onentwonthreenfournfivensixn’)).communicate()[0] I get: Traceback (most recent call last): File “<stdin>”, line 1, in ? File “/build/toolchain/mac32/python-2.4.3/lib/python2.4/subprocess.py”, line 533, in __init__ (p2cread, p2cwrite, File “/build/toolchain/mac32/python-2.4.3/lib/python2.4/subprocess.py”, line 830, in _get_handles p2cread = stdin.fileno() …

Total answers: 12