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

后端 未结 5 1783
温柔的废话
温柔的废话 2021-02-04 02:54

I usually do this in Perl:

whatever.pl

while(<>) {
    #do whatever;
}

then cat foo.txt | whatever.pl

Now, I

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 03:25

    Try this:

    import fileinput
    for line in fileinput.input():
        process(line)
    

提交回复
热议问题