'Can't move a file after i write to it in python

enter image description here

enter image description here

I try to move the file, after I write to it, but it don't work. Why?



Solution 1:[1]

Your file variable is being overwritten when you use the with statement: by the time you get to the shutil.move, it is not the original string anymore. To solve this, use 2 different variables (e.g filename for the original string)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rikyeah