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

Python ValueError: IO operation on closed file-LMLPHP

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

Python ValueError: IO operation on closed file-LMLPHP

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

运行结果如图所示:

Python ValueError: IO operation on closed file-LMLPHP

问题成功解决!

05-11 09:00