Whenever I try to write or modify the data of a file in any way I get this error everytime:
OSError: [Errno 9] Bad file descriptor
Here's what I've been trying to do:
# output.txt is the file already created inside of the same directory
with open(__file__.rsplit("\", 1)[0] + "\output.txt", "w") as f:
f.write("this should write to 'output.txt'")
I would try to dump with json or append with normal data but I'm continuously recieving the same error.
In the above example, here is the entire output of the terminal after execution:
C:UsersUSERDocumentsProgrammingCodePythonTesting>c:UsersUSERDocumentsProgrammingCodePythonTestingz_3.py
OSError: [Errno 9] Bad file descriptor
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UsersUSERDocumentsProgrammingCodePythonTestingz_3.py", line 4, in <module>
f.write("this should write to 'output.txt'")
OSError: [Errno 9] Bad file descriptor
This is all very strange because I've been able to write to files normally but I've just recently reinstalled windows and now it won't work.
question from:
https://stackoverflow.com/questions/65931766/why-can-i-suddenly-no-longer-write-to-files-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…