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...
Best practice with file is close and move, because if you will not close then it might be create problem in some OS, like Windows.
file
close
move
Windows
To make your code more portable, close file before move.