错误代码:
def load_stu(self):
try:
os.chdir('StudentManagerSystem')
f = open('student.data', 'r')
except:
f = open('student.data', 'w+')
# else:
finally:
data = f.read()
new_list = eval(data) # **** 不明白
self.student_list = [Student(i['name'], i['gender'], i['tel']) for i in new_list]
f.close()
报错提示:
in load_stu
new_list = eval(data) # **** 不明白
File "", line 0
SyntaxError: unexpected EOF while parsing
正确的方法:
def load_stu(self):
try:
os.chdir('StudentManagerSystem')
f = open('student.data', 'r')
except:
f = open('student.data', 'w+')
# else:
finally:
data = f.read()
new_list = eval(data) # **** 不明白
self.student_list = [Student(i['name'], i['gender'], i['tel']) for i in new_list]
f.close()