1,从管道读取文件
import fileinput for line in fileinput.input(): pass
import sys for line in sys.stdin: print line
2,逐行读取文件
for line in data: ... do stuff ...
line = data.readline() while line: # ... do stuff ... line = data.readline()