def get_gen_slice(ctx=Bubble(), iterable=[], amount=-1, index=-1):
    """very crude way of slicing a generator"""
    ctx.gbc.say('get_gen_slice', stuff=iterable, verbosity=10)

    i = -1
    # TODO
    # i = 0 #NATURAL INDEX, this will break all features with exports and -p

    if amount > 0:
        if index < 0:
            index = 0
    else:
        for item in iterable:
            i += 1
            item[buts('index')] = i
            ctx.gbc.say('Get gen NO slice:item %d' % i, verbosity=100)
            ctx.gbc.say('Get gen NO slice:a:%d i:%d' %
                        (amount, index), verbosity=100)
            ctx.gbc.say('Get gen NO slice:item', stuff=item, verbosity=1000)
            yield item

    until = index + amount
    if six.PY2:
        sli = xrange(index, until)
    else:
        sli = range(index, until)

    ctx.gbc.say('Get gen slice:range %s' % str(sli), verbosity=1000)

    # TODO: iterable should be empty if not slicing
    # if valid slice ...
    for item in iterable:
        i += 1
        if i in sli:
            ctx.gbc.say('Get gen slice:item %d' % i, verbosity=100)
            ctx.gbc.say('Get gen slice:a:%d i:%d' %
                        (amount, index), verbosity=100)
            ctx.gbc.say('Get gen slice:item', stuff=item, verbosity=1000)
            item[buts('index')] = i
            yield item
        elif i > until:
            break
        else:
            pass
def get_gen_slice ( ctx = Bubble ( ) , iterable = [ ] , amount = - 1 , index = - 1 ) : ctx . gbc . say ( 'get_gen_slice' , stuff = iterable , verbosity = 10 ) i = - 1 if amount > 0 : if index < 0 : index = 0 else : for item in iterable : i += 1 item [ buts ( 'index' ) ] = i ctx . gbc . say ( 'Get gen NO slice:item %d' % i , verbosity = 100 ) ctx . gbc . say ( 'Get gen NO slice:a:%d i:%d' % ( amount , index ) , verbosity = 100 ) ctx . gbc . say ( 'Get gen NO slice:item' , stuff = item , verbosity = 1000 ) yield item until = index + amount if six . PY2 : sli = xrange ( index , until ) else : sli = range ( index , until ) ctx . gbc . say ( 'Get gen slice:range %s' % str ( sli ) , verbosity = 1000 ) for item in iterable : i += 1 if i in sli : ctx . gbc . say ( 'Get gen slice:item %d' % i , verbosity = 100 ) ctx . gbc . say ( 'Get gen slice:a:%d i:%d' % ( amount , index ) , verbosity = 100 ) ctx . gbc . say ( 'Get gen slice:item' , stuff = item , verbosity = 1000 ) item [ buts ( 'index' ) ] = i yield item elif i > until : break else : pass
very crude way of slicing a generator