Python ValueError: IO operation on closed file

时间:2022-07-16 03:23:56

ValueError IO operation on closed file表示处理了已经被关闭的数据,在python 中 with语句的上下文会帮助处理,也就是说,当python的处理代码不对齐的时候会出现这种情况。例子如下:

Python ValueError: IO operation on closed file

header那一行,突出,也就是文件在之前一行关闭了。就会报错ValueError: IO operation on closed file。如图:

Python ValueError: IO operation on closed file

解决方法就是把header后移。如图:Python ValueError: IO operation on closed file

运行结果如图所示:

Python ValueError: IO operation on closed file

问题成功解决!