I only need to read the first line of a huge file and change it.
Is there a trick to only change the first line of a file and save it as another file using Python? A
The solution i would use is to use create a file missing old first line
from_file.readline() # and discard
shutil.copyfileobj(from_file, tail_file)
then create a file with the new first line
then use the following to concatenate the newfirstline file and tail_file
for f in ['newfirstline.txt','tail_file.txt']:
with open(f,'rb') as fd:
shutil.copyfileobj(fd, wfd, 1024*1024*10