Skip to content

Commit

Permalink
Fixes #195 max_len doesn't like empty iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Smith committed Mar 7, 2015
1 parent 1b55106 commit a587967
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions commands/local_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def run(results, cmdenv, tdb):
results.summary = ResultRow()
results.summary.near = srcSystem
results.summary.ly = ly
results.summary.stations = 0

distances = { srcSystem: 0.0 }

Expand Down Expand Up @@ -130,6 +131,7 @@ def station_filter(system):
row.dist = dist
row.stations = stations if showStations else []
results.rows.append(row)
results.summary.stations += len(row.stations)

return results

Expand Down
6 changes: 6 additions & 0 deletions formatting.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import absolute_import, with_statement, print_function, division, unicode_literals
import itertools

class ColumnFormat(object):
"""
Expand Down Expand Up @@ -165,6 +166,11 @@ def format(self, rowData):
return self.prefix + ' '.join(col.format(rowData) for col in self.columns)

def max_len(iterable, key=lambda item: item):
iterable, readahead = itertools.tee(iter(iterable))
try:
next(readahead)
except StopIteration:
return 0
return max(len(key(item)) for item in iterable)

if __name__ == '__main__':
Expand Down

0 comments on commit a587967

Please sign in to comment.