I have a generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse the generator several times....
How can I build a numpy array out of a generator object? Let me illustrate the problem: >>> import numpy >>> def gimme(): ... for x in xrange(10): ......
In python, how do I check if an object is a generator object? Trying this – >>> type(myobject, generator) gives the error – Traceback (most recent call last): File...
Is there a simple way of testing if the generator has no items, like peek, hasNext, isEmpty, something along those lines? 24 Answers 24
Can someone give me an example of why the “send” function associated with Python generator function exists? I fully understand the yield function. However, the send function is confusing...
The typical way to loop x times in JavaScript is: for (var i = 0; i < x; i++) doStuff(i); But I don’t want to use the ++ operator...
I’m starting to learn Python and I’ve come across generator functions, those that have a yield statement in them. I want to know what types of problems that these...
I want to change the following code for directory, dirs, files in os.walk(directory_1): do_something() for directory, dirs, files in os.walk(directory_2): do_something() to this code: for directory, dirs, files in...
I am reading the Python cookbook at the moment and am currently looking at generators. I’m finding it hard to get my head round. As I come from a...
I have a generator function like the following: def myfunct(): ... yield result The usual way to call this function would be: for r in myfunct(): dostuff(r) My question,...