Skip to content

Bug in stations.csv comment parsing / undocumented stations.csv layout constraints #27

@EvilRenegade

Description

@EvilRenegade

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.

In reality, the code

if row[0].startswith('#'):
    continue

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:

  1. Document the expected format for stations.csv and explicitly forbid empty lines.
  2. Do EAFP all the way: Wrap the entire thing in a try/catch block and swallow the IndexError.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions