generator slides review
andrea crotti
andrea.crotti.0 at gmail.com
Sun Feb 2 17:55:59 EST 2014
Thanks everyone for your feedback.
The talk I think went well, maybe I was too fast because I only used 21 minutes.
>From the audience feedback, there were some questions about my "Buggy
code" example, so yes probably it's not a good example since it's too
artificial.
I'll have to find something more useful about that or just skip this maybe.
For possible generators drawbacks though I could add maintanability,
if you start passing generators around in 3-4 nested levels finding
out what is the original source of can be difficult.
I'm also still not convinced by the definitions, which I tried now to
make clear and ay something like:
- and iterator defines *how you iterate* over an object (with the
__next__ method)
- an iterable defines *if you can iterate* over an object (with the
__iter__ method)
And when I do something like this:
class GenIterable:
def __init__(self, start=0):
self.even = start if is_even(start) else start + 1
def __iter__(self):
return self
def __next__(self):
tmp = self.even
self.even += 2
return tmp
it basically means that the a GenIterable object is iterable (because
of __iter__) and the way you iterate over it is to call the next
method on the object itself (since we return self and we define
__next__).
That seems clear enough, what do you think?
I might give this talk again so feedback is still appreciated!
More information about the Python-list
mailing list