The following is an article to share with you about solving the permission error problem of deleting files in python. It has a good reference value and I hope it will be helpful to everyone. Let’s take a look together
Using os.remove to delete files, I always encounter an error: PermissionError: WinError
I searched for a long time but couldn’t find the reason. I thought it was windows. The system problem was finally found to be caused by deleting a file that was not closed.
The code is as follows:
with open(front_pic_path,'rb') as f: pic_base64 = base64.b64encode(f.read()) #f.close() os.remove(front_pic_path)
Later I added the line f.close( ) is OK!
Related recommendations:
python method of deleting unnecessary python files
Unzip the zip file under python and delete the file Examples of _python
python Sharing of various handling methods for failed file deletion
The above is the detailed content of Solve the permission error problem of python deleting files. For more information, please follow other related articles on the PHP Chinese website!