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
后,文件没有删除它没有在本地目录中删除任何替代解决方案吗?
答案 0 :(得分:0)
您必须先关闭该文件,然后才能将其删除:
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'
您应该在致电f.close()
之前添加os.remove
,或者只使用with
:
with open(s,'rb') as f:
conn = tinys3.Connection("AKIAJPOZEBO47FJYS3OA","04IZL8X9wlzBB5LkLlZD5GI/",tls=True)
z = str(datetime.datetime.now().date())
x = z + '/' + s
conn.upload(x, f, 'crawling1')
os.remove(s)