while 1:
try:
#read from stdin
line = sys.stdin.readline()
except KeyboardInterrupt:
break
if not line:
break
fields = line.split('#')
...
如何跳过从stdin中读取的第一行?stdin
?
infile = sys.stdin
next(infile) # skip first line of input file
for line in infile:
if not line:
break
fields = line.split('#')
...
你可以使用 enumerate
函数,以对该。
for place, line in enumerate(sys.stdin):
if place: # when place == 0 the if condition is not satisfied (skip first line)
....
记载: 列举.