local.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:treadmill 作者: Morgan-Stanley 项目源码 文件源码
def _fragment_in_reverse(iterable, start=0, limit=None):
    """
    Selects a fragment of the iterable and returns the items in reverse order.

    The lowest index is 0 and designates the last line of the file.
    'Limit' specifies the number of lines to return.
    """
    # TODO: Naive implementation. Needs to be rewritten to a solution with
    # file pointer moving around etc. if it turns out that this isn't
    # performant enough.
    maxlen = None
    if limit >= 0:
        maxlen = start + limit

    fragment = collections.deque(iterable, maxlen)
    try:
        for _ in six.moves.range(start):
            fragment.pop()
    except IndexError:
        raise exc.InvalidInputError(__name__,
                                    'Index start=%s is out of range.'
                                    % str(start))

    fragment.reverse()
    return fragment
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号