def genWhile(g, condition):
    """
    run generator g while 'condition' is true.
    Condition is a partial expression such as "< 10"
    to be evaluated with g.next() as the left side
    """
    while 1:
        next = g.next()
        if eval("next " + condition):
            yield next
        else:
            return

    run generator g while 'condition' is true.
    Condition is a partial expression such as "< 10"
    to be evaluated with g.next() as the left side
    
recipes/Python/66427_wrap_unbounded_generator_restrict_its/recipe-66427.py