Skip to content Skip to sidebar Skip to footer

How Can I Pass A Variable From One Generator To Another In Python?

I have the following 2 generators: a = 20 def function1(): coin = np.random.randint(0, 100) a2= a+coin yield a2 def function2(): yield a2 I want to pass a2 to f

Solution 1:

I am not completly sure if this is what you are looking for, but generators have a method called 'send' which enables you to pass data to the generator. You might want to read this example. Pay attention to the functions 'consume' and 'produce'.


Post a Comment for "How Can I Pass A Variable From One Generator To Another In Python?"