with open(filepath, 'r') as file: reader= csv.reader(file) # print(reader) header = next(reader) #if we place this outside of the open, then it will through a ValueError: I/O operation on closed file. print(header)