def with_iter(iterable):
    """Wrap an iterable in a with statement, so it closes when consumed.

    >>> uplines = (line.upper() for line in with_iter(open(path, 'r')))
    >>> print('\n'.join(uplines))
    """
    with iterable:
        for item in iterable:
            yield item
Wrap an iterable in a with statement, so it closes when consumed.

    >>> uplines = (line.upper() for line in with_iter(open(path, 'r')))
    >>> print('
'.join(uplines))
    
recipes/Python/578342_Wrap_any_iterable_context_manager_so_it_closes/recipe-578342.py