I need to validate a text file uploaded on s3. I can read all lines in a file this way:
for line in response['Body'].iter_lines(chunk_size=50, keepends=False):
self.validate(line.decode("utf-8"))
But text files can be very large - up to 100000 irrelevant lines, while I only need to validate the first 10 and last 2 lines. Is there a way to read only those lines to save time/memory?