gpt4 book ai didi

python - 值错误: need more than one value to unpack

转载 作者:太空宇宙 更新时间:2023-11-03 16:43:50 24 4
gpt4 key购买 nike

我正在编写一个测验,在学生完成测验后,在保存分数时,我试图确保学生的最后三个分数保存到他们的名字中。如果他们之前没有完成过测验,则会在文本文件中为他们写入一个新行。

filename = (str(class_number) + 'txt')
with open(filename, 'a') as f:
f.write(str(name) + " : " + str(score) + '\n')

with open(filename) as f:
f.seek(0)
scores = f.readline()
from collections import deque
for line in scores:
name, score = line.rstrip('\n').split(',')
score= int(score)
if name not in filename:
filename[name] = deque(maxlen=3)
temp_q = filename[name]
temp_q.append(str(score))
filename[name] = temp_q

filehandle = open (filename, 'w')
for key,values in filename.iteritems():
filehandle.write(name + ',')
filehandle.write (','.join(list(values)) + '\n')
filehandle.close()

这是错误:

name, score = line.rstrip('\n').split(',')
Value error need more than 1 value to unpack

最佳答案

此错误消息表明您尝试读取的文件中没有 , 字符。

关于python - 值错误: need more than one value to unpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36531369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com