def SkipLastNItems(iterable, n):
    """
    Generator yielding all but the final n items of a finite stream.

    SkipLastNItems(iterable, n) -> iterator
        iterable -- a sequence, iterator, or some object which supports
            iteration, yielding items of any type.
        n -- an integer or None
    """
    def SLNI(iterable, n):
        items = list(iterable)[:-n]
        while items:
            yield items.pop(0)

    if n and n > 0:
        iterable = SLNI(iterable, n)
    return iterable