How to loop through a generator

Simply

for x in gen:
    # whatever

will do the trick. Note that if gen always returns True.


for item in function_that_returns_a_generator(param1, param2):
    print item

You don't need to worry about the test to see if there is anything being returned by your function as if there's nothing returned you won't enter the loop.