Generally, Windows won't let you delete a file if it's open somewhere, whether in the same process or in another process. You said the file becomes delete-able when you kill python, so I'm guessing that another part of your program (not shown) is holding the file open? You can always use something like Process Explorer [1] to determine exactly which process is holding a file lock. If it's your own Python program, look for a place that is doing a file open() call that is not using a context manager ("with" statement) or at least manually calling close().
If this block of code you showed is inside a "with open" call for that file, then that's the problem. [1] https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer On Sun, Nov 5, 2017 at 5:35 AM Henk Zevenhuizen <henk.zevenhui...@gmail.com> wrote: > Hi there, > > This is my first mail to this list and i have a huge problem. > > my os.remove(filename) is not working. > > i am running python27 32 bits on a windows 10 64 bits machine > > My piece of code (with debugging statements): > > raw_input('before...') > print 73, (os.path.join(VERWERKTDIR, orgname)) > > if os.path.isfile(os.path.join(VERWERKTDIR, orgname)): > os.remove(os.path.join(VERWERKTDIR, orgname)) > raw_input('after...') > > print 'file removed' > else: > print 'no file present'' > > > if there is a file to be removed i can see the print 'file removed' > however the file is still there > > when i get the message : 'before' i can delete the file through windows > explorer and with CTRL-Z i can restore the file > then i press <Enter> to continue the raw_input('before...') > > Then i get the message: "after", the file is still there and i cannot > delete the through windows explorer (permission denied) > the only way to delete the file is killing python > > I don't have the slightest idea where to look > > Has anyone any idea ?? > > thanks in advance > > Henk Zevenhuizen > Holland > > > > > > > _______________________________________________ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 >
_______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32