Python ValueError: IO operation on closed file

Posted 小花花108

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python ValueError: IO operation on closed file相关的知识,希望对你有一定的参考价值。

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

clip_image002

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

clip_image004

解决方法就是把header后移。如图:clip_image006

运行结果如图所示:

clip_image008

问题成功解决!

以上是关于Python ValueError: IO operation on closed file的主要内容,如果未能解决你的问题,请参考以下文章