Teacher’s code:
try:
import os
os.chdir(r'D:\\y')
list1 = list(open('score_1 .txt'))
file1 = open('score_2.txt','w')
del(list1[0]) #删除的是list1的第一行,原本的score_1.txt没有变化
file1.write("number\\tEnglish score\\n")
for s in list1:
x = s.split() #按照空格来切片分组
x[1] = int(x[1]) + 20
file1.write(f'{x[0]}\\t{x[1]}\\n')
#[Errno 2] No such file or directory: 'score_1 .txt'
except IOError as e:
print(e)
#[WinError 2] 系统找不到指定的文件。: 'D:\\\\y'
except OSError as ee:
print(ee)
#No module named 'os' -- 一般很少使用
except ImportError as eee:
print(eee)
except BaseException as eeee:
print(eeee)
else:
file1.close()
os.system('notepad score_2.txt')
(But I have a macOS so it wouldn’t run)