-2
f=open('julyTemps.txt')
for li in f.readlines():
   data = li.strip().split(' ')
   print data[1]

此代码给我一个超出范围的错误,列表长度为 3。请帮助

4

1 回答 1

1
with open('julyTemps.txt', 'r') as f:
    for line in f:
        data = line.strip().split(' ')
        if len(data) > 1
            print data[1]
        else:
            print 'this line does not split as it should:\n%s' % line
于 2013-04-26T08:44:20.070 回答