目前对Python来说还很新。我正在使用for循环更新文本文件。我试图一次用多个数组更新列表。
尝试接收以下错误...
ValueError: too many values to unpack (expected 3)
到目前为止,这是我的代码:
import csv, math, ast
#Declaring where our data is stored
statsFile = 'stats.csv'
#Creating a list of our teams
team_list = []
ORtg_list = []
DRtg_list = []
k = open('team_list.txt', 'w')
k.write("""{
""")
#Opening csv to read the file
csvRead = csv.reader(open(statsFile))
next(csvRead)
#Populating our team_list array with team names and averages
for row in csvRead:
if row[1] not in team_list:
team_list.append(row[1])
ORtg_list.append(row[10])
DRtg_list.append(row[11])
team_list.sort()
ORtg_list.sort()
DRtg_list.sort()
#Also adding the below lines to our team_list.txt
for team, ORtg, DRtg in team_list, ORtg_list, DRtg_list:
k.write(""" '%s': {'ORtg': '%s', 'DRtg': '%s'},
""" % (team, ORtg, DRtg))
k.write("}")
k.close()
team_list包含字符串(篮球队名称)。而ORtg和DRtg包含浮点数。
任何帮助将不胜感激!愿意在需要时提供更多信息。