How do I iterate over all lines of files passed on the commandline in Python?

Posted by Tg on Stack Overflow See other posts from Stack Overflow or by Tg
Published on 2009-04-03T19:15:37Z Indexed on 2010/06/13 16:52 UTC
Read the original article Hit count: 190

Filed under:
|

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?

Thanks.

EDIT:

Thanks, I like every single solution.

© Stack Overflow or respective owner

Related posts about python

Related posts about stdin