예제 #1
0
def lines_in_file(path, limit=float('inf'), desc=None, compute_total=True):
    from gtd.chrono import verboserate
    if compute_total:
        total = min(num_lines(path), limit)  # compute total lines in file
    else:
        total = None
    with codecs.open(path, 'r', encoding='utf-8') as lines:
        if desc:
            lines = verboserate(lines, desc=desc, total=total)
        if limit:
            lines = truncated(lines, limit)
        yield lines
예제 #2
0
def test_truncated():
    items = [1, 3, 1, 2, 2, 4]
    assert list(truncated(items, 3)) == [1, 3, 1]
    assert list(truncated(items, 0)) == []