Python DictRead

Why doesn’t this work?

import csv

with open(‘LabInstrumentList.csv’, ‘r’) as instrumentCsv:
instrumentList = csv.DictReader(instrumentCsv)
for row in instrumentList:
print(row)

I am getting the following error:

ValueError: I/O operation on closed file.

I don’t know why it doesn’t show my indents. but the 3rd line of code is within the “with” and the “for” is outside the “with”. And the “print” is within the “for”.

I moved this topic to the Python subforum.

To display your code with indents, enclose it in triple backticks or use the </> code button in the menu.

use formatter
the issue is that the print statement is inside the for loop

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.