解决python删除文件的权限错误问题
作者:yuanlulu 时间:2023-09-06 07:33:36
使用os.remove删除文件,总是遇到错误:PermissionError: WinError
找了很久没找到什么原因,以为是windows系统的问题,最后发现是删除了一个没有关闭的文件引起的。
代码如下:
with open(front_pic_path,'rb') as f:
pic_base64 = base64.b64encode(f.read())
#f.close()
os.remove(front_pic_path)
后来我增加了那行f.close()就OK啦!
来源:https://blog.csdn.net/yuanlulu/article/details/79694646
标签:python,删除,文件,权限,错误
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python调用文件时找不到相对路径的解决方案
2021-08-21 14:38:24
![](https://img.aspxhome.com/file/2023/9/124389_0s.png)
详解Django中views数据查询使用locals()函数进行优化
2021-01-21 00:53:13
vue实现Input输入框模糊查询方法
2024-04-28 09:20:46
![](https://img.aspxhome.com/file/2023/2/133112_0s.png)
跨浏览器的inline-block[译]
2009-03-11 21:04:00
![](https://img.aspxhome.com/file/UploadPic/20093/11/01-74s.jpg)
python用类实现文章敏感词的过滤方法示例
2022-04-10 19:30:25
![](https://img.aspxhome.com/file/2023/9/95309_0s.png)
注意import和from import 的区别及说明
2024-01-01 21:26:44
Python学习之日志模块详解
2022-06-24 09:20:22
![](https://img.aspxhome.com/file/2023/9/77889_0s.jpg)
一文详解前端进阶之IntersectionObserver
2024-05-03 15:07:48
![](https://img.aspxhome.com/file/2023/0/130520_0s.png)
宽屏不是用来阅读的
2009-04-05 15:59:00
python 输出所有大小写字母的方法
2021-01-05 01:02:57
Pandas.DataFrame时间序列数据处理的实现
2022-09-20 08:43:41
Python实现TCP通信的示例代码
2022-10-03 15:49:17
PyQt5+Caffe+Opencv搭建人脸识别登录界面
2022-06-18 01:42:25
![](https://img.aspxhome.com/file/2023/5/103075_0s.jpg)
基于Python实现的恋爱对话小程序详解
2023-01-14 11:08:38
![](https://img.aspxhome.com/file/2023/8/134798_0s.png)
Python3 hashlib密码散列算法原理详解
2021-07-06 12:59:55
![](https://img.aspxhome.com/file/2023/9/65869_0s.png)
微信小程序实现图片上传功能
2023-09-06 13:08:44
基于Python编写一个B站全自动抽奖的小程序
2021-05-03 02:11:07
![](https://img.aspxhome.com/file/2023/8/79788_0s.jpg)
Python中的多线程实例(简单易懂)
2021-12-07 04:09:47
![](https://img.aspxhome.com/file/2023/7/80447_0s.png)
python中使用smtplib和email模块发送邮件实例
2022-09-16 05:37:23
Flask中基于Token的身份认证的实现
2022-11-20 06:45:53