问题遇到的现象和发生背景
麻烦帮我看看问题出在哪里了。
我自学Python心血来潮,想通过代码实现输入六位数,来和 .txt里的保存在字典中的六位数字对比是否相同。
以下代码基本实现了我想要的功能,但出现了报错。我在网上找了许多解释都没搞明白为什么报错!
用代码块功能插入代码,请勿粘贴截图
import json
password_filename = 'student.txt'
mima_query = []
password = 271381
with open(password_filename, 'r', encoding='utf-8') as readfile:
mima1 = readfile.readlines()
for item in mima1:
d = json.loads(item)
if d['mima'] != password:
mima_query.append(d)
print(mima_query)
else:
print(1)
.txt文件内容如图:
运行结果及报错内容
我的解答思路和尝试过的方法
我把第十一行的d = json.loads(item)改成了d = dict(eval(item))还是出错:
出现了这个错误:
我想要达到的结果
该怎么解决程序的报错的问题?为什么报错?尝试也报错了为什么?