如题,Crossin的编程教室【Python 第33课】 处理文件中的数据 这篇文章最后的源码我复制下来运行,结果py3报错。
源码内容:
f = file('scores.txt') lines = f.readlines() #print lines f.close()
results = []
for line in lines: #print line data = line.split() #print data
sum = 0 for score in data[1:]: sum += int(score) result = '%s \t: %d\n' % (data[0], sum) #print result
results.append(result)
#print results output = file('result.txt', 'w') output.writelines(results) output.close()
报错内容:
RESTART: C:\Users\Administrator\AppData\Local\Programs\Python\Python36\title 31.py
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\title 31.py", line 15, in <module>
sum += int(score)
ValueError: invalid literal for int() with base 10: 'scores.txt'
>>>
|