正在回答
同学,您好,看同学的报错情况,

我猜测同学的txt文档最后可能存在空行之后在空格的情况,同学可删除之前的考试成绩.txt文档,重新创建个考试成绩.txt文档,复制粘贴下列数据到考试成绩.txt,粘贴完成之后,直接关闭该文档,注意:粘贴时看光标是否自动定位在文档开头,粘贴完成直接关闭文档。
620,王伟,2-1,96,89,75
621,赵芳芳,2-1,71,62,80
622,徐丽丽,2-2,78,95,69
623,张倩,2-2,96,88,89
624,胡倩倩,2-2,98,99,100
625,赵晓婷,2-3,91,87,89
626,李伟,2-3,53,68,67
627,王秀英,2-4,86,87,87
628,李静,2-4,65,68,74
629,郭楠楠,2-4,78,81,94
630,邓逸凡,2-4,70,66,61
如果我的回答解决了您的疑惑,望采纳!!^_^ 祝学习愉快~~~~~
from redis_db import pool
import redis
con = redis.Redis(
connection_pool=pool
)
try:
file = open(file="考试成绩.txt", mode="r", encoding="utf-8")
data = file.read().splitlines()
for index in data:
temp = index.split(",")
sid = temp[0]
name = temp[1]
class_no = temp[2]
score_1 = int(temp[3])
score_2 = int(temp[4])
score_3 = int(temp[5])
if score_1 >= 85 and score_2 >= 85 and score_3 >= 85:
con.hmset(sid, {"name": name, "class_no": class_no,
"语文": score_1, "数学": score_2, "外语": score_3})
print("执行成功!")
except Exception as e:
print(e)
finally:
if "file" in dir():
file.close()
del con-------------------------------------------------------------------------------
620,王伟,2-1,96,89,75
621,赵芳芳,2-1,71,62,80
622,徐丽丽,2-2,78,95,69
623,张倩,2-2,96,88,89
624,胡倩倩,2-2,98,99,100
625,赵晓婷,2-3,91,87,89
626,李伟,2-3,53,68,67
627,王秀英,2-4,86,87,87
628,李静,2-4,65,68,74
629,郭楠楠,2-4,78,81,94
630,邓逸凡,2-4,70,66,61
- 参与学习 人
- 提交作业 625 份
- 解答问题 2669 个
数据库作为企业储存和管理数据的根本,掌握数据库是每个开发工程师必备的技能,本阶段带你学会用Python操作MySQL、Redis和MongoDB三大主流数据库。夯实数据库基础。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星