while 1:
try:
#read from stdin
line = sys.stdin.readline()
except KeyboardInterrupt:
break
if not line:
break
fields = line.split('#')
...
如何跳过stdin
的第一行阅读?
答案 0 :(得分:5)
infile = sys.stdin
next(infile) # skip first line of input file
for line in infile:
if not line:
break
fields = line.split('#')
...
答案 1 :(得分:3)
您可以使用enumerate
功能来实现:
for place, line in enumerate(sys.stdin):
if place: # when place == 0 the if condition is not satisfied (skip first line)
....
enumerate的文档。