Read a File 8 Lines at a Time Python
Question: Hello I am trying to read a file in Python 8 lines at a time and use the
current 8 lines as str variables

However I am unable to do this correctly and would appreciate any help

    
    
    with open("test.txt", 'r') as infile:
        lines_gen = islice(infile, 8)
        for lines in lines_gen:
            firstname = str(lines[0])
            lastname = str(lines[1])
            email = str(lines[2])
    

...

How can I achieve this

*cheers

And ty for any help


Answer: Using the usual n things at a time pattern

    
    
    from itertools import izip
    
    with open("test.txt") as f:
        line_gen = izip(*[f]*8)
        for lines in line_gen:
            print lines
            firstname, lastname, email, fourth, fifth, sixth, seventh, eighth = lines
            ...
    

