请教一下学Python时遇到ValueError: I/O operation on closed file.不知道咋解决

请教一下学时Python遇到ValueError: I/O operation on closed file.不知道咋解决

img

ValueError: I/O operation on closed file。是指处理了已经被关闭的数据。
with语句退出时上下文时会关闭文件。你应该嵌套使用在其下的所有代码(将 for 语句 移动到 with 语句下面):

import csv 
with open('score.csv',encoding="utf-8") as dc:
    reader=csv.reader(dc)
    for x in reader:
        print(x)