Solve the permission error problem of python deleting files

不言
Release: 2018-04-24 13:39:47
Original
3997 people have browsed it

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!