python WindowsError: [Error 32]

created at 06-27-2021 views: 1

description

code:

import os
file_open = open('F:/input1.txt')
os.remove("F:/input1.txt")   

error message:

WindowsError: [Error 32] : 'F:/input1.txt' 

reason

When investigating the reason, I found that when I deleted this file, I haven't close the opening file before.

solution

At this time, I close the open file before deleting it. code show as below:

import os
file_open = open('F:/input1.txt')
file_open.close()
os.remove("F:/input1.txt")

then we can avoid the [Error 32] error

Please log in to leave a comment.