What is the correct fix?
with open(path) as f:
data = f.read()
print(f.closed)
rows = data.split("\n")[1:]
- Strip first so a trailing blank line goes
- Strip first so a leading header line goes
- Read the file with
f.readlines()here - Move
rows = ...inside the with block
A file usually ends with a newline, so split leaves an empty final row; strip it first.
Play Problem Solving ▸