runtime
316 / 500
question 316 Iterators & Generators · medium

A station file you can only read once

StationFile(path) lets reports loop over a station's daily readings: for day, tmax in StationFile("chicago.csv"). Two problems: a loop crashes with ValueError: not enough values to unpack at the end of the file instead of stopping, and a second loop over the same object gets nothing. It also never closes the file. Fix the class so every loop reads the whole file, from the line after the header, and closes it.

ClassStationFile(path); the file has a header line date,tmax_c and then YYYY-MM-DD,number lines, perhaps with blank lines
Each loopyields (date, tmax) with tmax a float, for every non-blank line after the header

Loading your progress…

A station file you can only read once — Python practice · Runtime