def read_large_file(file_object): # Define read_large_file()
“””A generator function to read a large file lazily.”””
file_object.readline() # Skip the header line
# Loop indefinitely until the end of the file
while True:
# Read a line from the file: data
data = file_object.readline()
# Break if this is the end of the file
if not data:
break
# Yield the line of data
yield data
with open(‘world_dev_ind.csv’) as file: #Open a connection to the file
# Create a generator object for the file: gen_file
gen_file = read_large_file(file)
# Print the first three lines of the file
print(next(gen_file))
print(next(gen_file))
print(next(gen_file))
in the above code the line-
Skip the header line
file_object.readline()
will it not omit one line from the data every time we apply next() on the generator function.
expecting to get the correct answer to this question
Sakshi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.