def generate_batches(sequence, batch_len=<NUM_LIT:1>, allow_partial=True, ignore_errors=True, verbosity=<NUM_LIT:1>):
it = iter(sequence)<EOL>last_value = False<EOL>while not last_value:<EOL><INDENT>batch = []<EOL>for n in range(batch_len):<EOL><INDENT>try:<EOL><INDENT>batch += (next(it),)<EOL><DEDENT>except StopIteration:<EOL><INDENT>last_value = True<EOL>if batch:<EOL><INDENT>break<EOL><DEDENT>else:<EOL><INDENT>raise StopIteration<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>if verbosity > <NUM_LIT:0>:<EOL><INDENT>print_exc()<EOL><DEDENT>if not ignore_errors:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>yield batch<EOL><DEDENT>
Iterate through a sequence (or generator) in batches of length `batch_len`

    http://stackoverflow.com/a/761125/623735
    >>> [batch for batch in generate_batches(range(7), 3)]
    [[0, 1, 2], [3, 4, 5], [6]]