You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The stock stations.csv begins with a comment, rather than a typical CSV column header row.
This sets the expectation that there is a certain amount of formatting freedom, as long as the actual lines are properly formatted.
makes the assumption that there is a row that has been taken apart, erroring out with an unhandled IndexError: list index out of range if the line is empty.
As far as I see, there are three options to mitigate this:
Document the expected format for stations.csv and explicitly forbid empty lines.
Do EAFP all the way: Wrap the entire thing in a try/catch block and swallow the IndexError.
Go LBYL: Turn the condition into if (len(row) > 0) and row[0].startswith('#'):, thus avoiding the leap into darkness.
Personally, I'd opt for 3, but I'm a regular programmer. I'm certain Python fundamentalists would urge you to go for 2.