f=open('julyTemps.txt')
for li in f.readlines():
data = li.strip().split(' ')
print data[1]
此代码给出了超出范围的错误,列表的长度为3。 请帮忙
答案 0 :(得分: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