Decorators
and
Generators
But why?
- Decorators
- Make a bunch of functions and/or methods to do the same thing
- Generators
- Create iterators. Vital for large data sets.
- Jobs!
- Standard interview question
- Once upon a time...
A quick bit of background
This may be revision, but it's important
Everything in
Python is an object
No really, everything
- Numbers
- Strings
- Instances
- Classes
- Class methods
- Functions
- Modules you've imported

Being an object in python
- Have your own doc (try doc(anything))
- Having lots of built in methods
- Most importantly for us,
- you can be passed around and modified
What we're actually doing with generators
- A decorator is a thing* that takes a function and returns another function
- The new function will do everything the old function does, plus some other stuff
- Every function passed through the same decorator will have the same new functionality
*it's a function, but if I said that up there it'd be confusing
Phew, that was a lot to take in,
have a cute picture

deck
By Sorcha Bowler
deck
- 795