Skip to content Skip to sidebar Skip to footer

Python Shutil Copy Function Missing Last Few Lines

I have a python script that generates a large text file that needs a specific filename that will FTPd later. After creating the file it copies it to a new location while modifying

Solution 1:

You must make sure that whatever creates file1.txt has closed the file handle.

File writing is buffered, and if you do not close the file, the buffer is not flushed. The missing data at the end of a file is still sitting in that buffer.

Preferably you ensure that the file is closed by using the file object as a context manager:

withopen('file1.txt', 'w') as openfile:
    # write to openfile# openfile is automatically closed once you step outside the `with` block.

Post a Comment for "Python Shutil Copy Function Missing Last Few Lines"