【发布时间】:2017-10-21 19:57:22
【问题描述】:
文件 score.txt 的内容,列出了玩家在某场比赛中的表现:
80,55,16,26,37,62,49,13,28,56
43,45,47,63,43,65,10,52,30,18
63,71,69,24,54,29,79,83,38,56
46,42,39,14,47,40,72,43,57,47
61,49,65,31,79,62,9,90,65,44
10,28,16,6,61,72,78,55,54,48
以下程序读取文件并将分数存储到列表中
f = open('scores.txt','r')
L = []
for line in f:
L = L + map(float,str.split(line[:-1],','))
print(L)
但它会导致错误消息。我在课堂上得到的代码非常困惑,对 Pyton 来说非常陌生。 我可以修复代码吗?
【问题讨论】:
-
“导致错误消息”您想与我们分享它们吗?
-
你应该使用
with open('scores.txt', 'r')
标签: python python-3.x mapping