问题遇到的现象和发生背景
这个错误是什么意思?
问题相关代码,请勿粘贴截图
def delete():
while True:
studeng_id=input('请输入你要删除的学生id:')
if studeng_id!='':
if os.path.exists(filename):
with open(filename,'r',encoding='utf-8')as rfile:
studeng_old=rfile.readline()
else:
studeng_old=[]
flag=False
if studeng_old:
with open(filename,'w',encoding='utf-8') as wfile:
d={}
for item in studeng_old:
d=dict(eval(item))
if d['id']!=studeng_id:
wfile.write(str(d)+'\n')
else:
flag=True
if flag:
print(f'id为{studeng_id}的学生已被删除!')
else:
print(f'没有找到id为{studeng_id}的学生!')
运行结果及报错内容
Traceback (most recent call last):
File "C:\Users\1\PycharmProjects\pythonProject4\venv\Scripts\stusystem.py", line 123, in <module>
main()
File "C:\Users\1\PycharmProjects\pythonProject4\venv\Scripts\stusystem.py", line 23, in main
delete()
File "C:\Users\1\PycharmProjects\pythonProject4\venv\Scripts\stusystem.py", line 89, in delete
d=dict(eval(item))
File "<string>", line 1
{
^
SyntaxError: '{' was never closed
我的解答思路和尝试过的方法
上面说语法错误,可我找不要89行的代码哪里有误