import csv
with open('MOCK_DATA.csv','r') as f:
mockDataReader = csv.reader(f)
lineCount = 1
for row in mockDataReader:
if lineCount > 1:
print(row)
lineCount += 1
It gives me an error. Here is the error message:
Traceback (most recent call last):
File "c:\Users\python programe\.vscode\readingCsvfile.py", line 8, in <module>
for row in mockDataReader:
ValueError: I/O operation on closed file.
The with context block closes the file when you exit it. You should nest all the following code that uses the reader you've opened under it:
with open('MOCK_DATA.csv','r') as f:
mockDataReader = csv.reader(f)
lineCount = 1
for row in mockDataReader:
if lineCount > 1:
print(row)
lineCount += 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With