Note that there are some explanatory texts on larger screens.

plurals
  1. POpython can't remove a file after closing it, "being used by another process"
    primarykey
    data
    text
    <p>I am trying to remove a file after reading from it, but getting "WindowsError: [Error 32] The process cannot access the file because it is being used by another process"</p> <pre><code>file = open(self.filePath) for line in file: #do things file.close() os.remove(self.filePath) #throws error os.rename(self.filePath, self.filePath + "old") #throws same error </code></pre> <p>any ideas?? </p> <p>thank you!</p> <p>UPDATE: i just restarted my (windows 7) box, started eclipse, moved os.remove("c:\file\file.txt") to the first line of my script, ran and got the same error. </p> <p>UPDATE 2: i used windows explorer to navigate to the file.. first time I couldn't delete it, it was being used by "System". second attempt the delete worked fine. the file is no longer there. now when I run os.remove("c:\file\file.txt") WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\file\file.txt' then i look in windows explorer and the file is back, empty. i can delete in explorer, then when i run the script to remove, it throws the error (and creates the empty file). any idea what could be going on here?</p> <p>UPDATE 3: i am an idiot. i was opening the file in the initialization of an object when i tested by moving the "remove" to top of script, i should have put it at the top, not after creating my objects </p> <p>sorry for taking your time, i've been working on something all weekend that's due tomorrow and panicked when it wouldn't run</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload