opath = ipath + '.new'
with open(ipath, 'rb') as fin:
    with open(opath, 'wb') as fout:
        delete_eof(fin, fout)
How to process huge text files that contain EOF / Ctrl-Z characters using Python on Windows?