I am writing a python program to copy a file line by line into a new file. The code I have is below in which I am using a loop to copy the file line by line.
Howeve
See shutil module for better ways of doing this than copying line-by-line:
shutil.copyfile(src, dst)Copy the contents (no metadata) of the file named src to a file named dst. dst must be the complete target file name; look at shutil.copy() for a copy that accepts a target directory path. If src and dst are the same files,
Erroris raised. The destination location must be writable; otherwise, anIOErrorexception will be raised. If dst already exists, it will be replaced. Special files such as character or block devices and pipes cannot be copied with this function. src and dst are path names given as strings.
Edit: Your question says you are copying line-by-line because the source file is volatile. Something smells wrong about your design. Could you share more details regarding the problem you are solving?