首页 > 解决方案 > 为什么我会收到此错误 OSError: [Errno 9] Bad file descriptor?使用 f.close() 关闭文件时发生

问题描述

在关闭文件时,我得到了这个 OSError。谁能解释出了什么问题?

>>> f=open('fr.txt','w')
>>> print('hey',file=f)
>>> f.close()


OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 9] Bad file descriptor

标签: python-3.x

解决方案


推荐阅读