Alex Rivera | Logout

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

Asked 2009-04-03T19:15:37.287
21

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 in Perl. How can I read the input?

Edit
Report

1 Answer

4
import sys

for line in sys.stdin:
    # do stuff w/line
answered 2009-04-03T19:20:46.247

Your Answer