Back
I usually do this in Perl:
whatever.pl
while(<>) { #do whatever;}
while(<>) {
#do whatever;
}
then cat foo.txt | whatever.pl
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?
sys.stdin
You can use this:
import fileinputfor line in fileinput.input(): process(line)
import fileinput
for line in fileinput.input():
process(line)
31k questions
32.8k answers
501 comments
693 users