Why are values ​​removed from the fields tuple after using the zip() function? How to avoid it?

 from openpyxl import load_workbook wb2 = load_workbook('sample.xlsx') ws = wb2.active fields = (cell.value for cell in ws['1']) # Тут есть значения в fields for f in fields: print (f) cellsIter = iter(ws.values) next(cellsIter) for i in cellsIter: for k, v in zip(fields, i): pass # В этом месте уже ничего нет в fields for f in fields: print (f) 

    1 answer 1

    Because the expression fields = (cell.value for cell in ws['1']) saves not a tuple, but a generator to the fields variable. Correct for fields = tuple(cell.value for cell in ws['1']) or fields = [cell.value for cell in ws['1']] .