I am trying to copy and paste information from bytes X to Y from a huge data file to a new file. I got X and Y by using f.readline() and f.tell(). Is there a faster way to do this then the code below.
import os
a = 300 # Beginning Byte Location
b = 208000 # Ending Byte Location
def file_split(x,y):
g = open('C:/small_file.dat', 'wb')
with open('C:/huge_data_file.dat', 'rb') as f:
f.seek(x, os.SEEK_SET) # Sets file pointer to x
line = '-1'
while (line != '') # line = '' would indicate EOF
while (f.tell() < y):
g.write(f.read(1))
g.close()
file_split(a,b)