Overview
Syllabus
Intro
I teach Python!
The dumbest function in the world
Bytecode from our function
Resume?
"yield" changes everything
Resume is back!
The iterator protocol
Generators implement this protocol
Calling iter() gets an object's iterator
"next" advances the generator
fib
read_n
next_vowel
So, when do we use generators?
Using our generator with "send"
How can I use coroutines?
Coroutine as "nanoservices"
Example: MD5
Coroutine example 1: MD5
Coroutine example 2: Weather
Coroutine example 2.1: Weather
When we get to the end of the list...
The "throw" method
Revisiting the weather
Refactoring our generator
"yield from" to the rescue!
What about asyncio?
Should you use coroutines?
Questions?
Taught by
PyCon US