let me highlight the problem with the following code:
def genny():
yield 1
yield 2
yield 3
def middleman(input_gen=None):
if input_gen:
gen = input_gen
else:
gen = genny()
return [next(gen), gen]
if __name__ == '__main__':
pro_list = middleman()
pro_value = pro_list[0]
print pro_value
pro_gen_id = pro_list[1]
for i in range(2):
pro_list = middleman(pro_gen_id)
pro_value = pro_list[0]
print pro_value
The restriction I have is that the middleman() function cannot be a generator but I need to display all values from the generator genny(). I did this by passing back the generator object to the main() function and then sending that back again to middleman(). Is this the optimum way to do this or are there any better ways?