If I open a file
fileObj = open(test.txt, 'wb+')
and write some stuff in it
fileObj.write(someBytes)
then decide to move it somewhere else
shutil.move('test.txt', '/tempFolder')
and then keep writing in it
fileObj.write(someMoreBytes)
what happens?
A couple observations:
- It seems like the file at
/tempFolder/test.txt
only contains the first set of bytes that were written. - After the file has been moved, it seems like the first set of bytes are deleted from the file object
- Subsequent writing on the file object after the file has been moved do not seem to create a new file on disk at
test.txt
, so what happens with those bytes? They stay in memory in the file object?
Now my main question is: how do I keep the same file object to write on the moved file? Because essentially the file is the same, it has only change location. Or is that not possible?
Thanks for the help!