jeudi 30 avril 2015

If-Condition Raising Exception

Is there a way to ask if a statement raises an exception? I'm trying to remove iterables from a list the moment they run out of elements to generate in.

x, iterables = 0, [iter(arg) for arg in args]
while True:
    try:
        if x >= len(iterables):
            break
        for iterable in iterables:
            yield next(iterable)
    except StopIteration:
        x += 1

Aucun commentaire:

Enregistrer un commentaire