I have code like this:
with open(\'foo.txt\') as file:
...do something with file...
...move foo.txt to another place while it\'s still open...
On Windows:
>>> import os
>>> with open('old.txt') as file:
os.rename('old.txt', 'new.txt')
Traceback (most recent call last):
File "", line 2, in
os.rename('test.txt', 'newtest.txt')
WindowsError: [Error 32] The process cannot access the file because it is being used by another process
You can't move the file, because someone(you) is already holding it. You need to close the file before you can move it.