0

This is my code:

    f = gzip.open('nome_file.gz','r')

    line = f.readline()

    for line in f:
            line = f.readline()
            line = line.strip('\n')
            if not line: break
            elements = line.split(" ")
            print elements[0]," ",elements[1]," ",elements[44]," ",elements[45]

    f.close()

I really don't know why just one line over two is read.

4

1 回答 1

4

for line in f:读取一行。下一行line = f.readline()读取下一行并将其存储在同一个变量中。

您阅读每一行,但每隔一秒跳过一次。

简单地丢弃line = f.readline()应该可以解决问题。

于 2013-11-14T10:18:27.467 回答