Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (45.3k points)

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?

1 Answer

0 votes
by (16.8k points)

You can use this:

import fileinput

for line in fileinput.input():

    process(line)

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...