1

while closing the file I get this OSError. Can anyone explains what's going wrong?

>>> 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
  • What Python version are you using? What operating system? Does the file exist already? Can you write to other files? Does it happen reliably with this file? I can run this code on my machine with no errors (after creating a fr.txt file), so there's something else going on. – Patrick Haugh Jul 13 '18 at 17:03
  • Possible duplicate of [What can lead to "IOError: \[Errno 9\] Bad file descriptor" during os.system()?](https://stackoverflow.com/questions/7686275/what-can-lead-to-ioerror-errno-9-bad-file-descriptor-during-os-system) – Evan Carroll Nov 08 '18 at 01:55

0 Answers0