deleting a file after uploading to s3 in python
Question: 
    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)   
    

The file is not deleting after i upload to `s3` it is not deleting in the
local directory any alternate solutions?


Answer: You have to close the file before you can delete it:

    
    
    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'
    

You should add `f.close()` before the call to `os.remove`, or simply use
`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)
    

