0

Why this simple code:

# Python 3.11.4

file = open('pe.txt','w')
file.write("que")
file.close()

That opens a text file called o, writes "que" and closes, launches error: OSError: [Errno 9] Bad file descriptor in file.close(), any ideas?

pe.txt has read and write permissions and is not open.

rVan
  • 27
  • 4
  • 1
    Did you have any code or subprocess to close the file descriptor (ie `os.close(file.fileno())`) prior to the line `file.close()`? The error seems to be due to the OS attempt to close a file that's not open. – tax evader Jul 15 '23 at 02:03
  • 3
    We need a [MRE] complete enough to cause the problem when run on someone else's Python interpreter. Code that only causes the problem _for you_ can't be used to test fixes or further investigate the problem (as by running syscall-level tracing). – Charles Duffy Jul 15 '23 at 02:11
  • So, let me explain, my project is located in Documents\e, when i run `file = open("pe.txt", "w")` it says the thing that it can open no file there, ok. When i run my program in Downloads\e, IT CREATES THE FILE, AND I CAN EDIT IT SUCESSFULY, why is this happening? Can be One Drive? – rVan Jul 15 '23 at 02:32

0 Answers0