2024-09-30 20:34:36 发布
网友
def upload(s): conn=tinys3.Connection("AKIAJPOZEBO47FJYS3OA","04IZL8X9wlzBB5LkLlZD5GI/",tls=True) f = open(s,'rb') z=str(datetime.datetime.now().date()) x=z+'/'+s conn.upload(x,f,'crawling1') os.remove(s)
在我上传到s3之后,文件没有删除。它没有在本地目录中删除任何替代解决方案?在
s3
必须先关闭文件,然后才能删除它:
import os a = open('a') os.remove('a') >> Traceback (most recent call last): File "main.py", line 35, in <module> os.remove('a') PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'a'
您应该在调用os.remove之前添加f.close(),或者简单地使用with:
os.remove
f.close()
with
必须先关闭文件,然后才能删除它:
您应该在调用
^{pr2}$os.remove
之前添加f.close()
,或者简单地使用with
:相关问题 更多 >
编程相关推荐