Content¶
Comprehensions¶
The principle comes from the functional language Haskell but integrates very well into Python. After list comprehension came generator expressions followed by dictionary and set comprehensions.
The course introduces this style of programming with examples focusing on advantages and disadvantages for certain tasks.
Iterators and Generators¶
Iterators and generator make lazy evaluation, that is generating an object just when it is needed, very convenient. The concept of yielding instead of returning plays a central role. The course shows how to use generators to simplify programming tasks. Furthermore, coroutines will be used to implement concurrent solutions. An overview over the itertools module shows how to elegantly solve iteration tasks.
Decorators¶
Decorator provide a very useful method to add functionality to existing functions and classes. The course uses examples for caching, proxying, and checking of arguments to demonstrate how decorators can improve code readability and can simplify solutions.
Context Managers¶
The with statement helps to make code more robust by simplifying exception handling. The course shows how to use the with statement with the standard library and how to write your own objects that take advantage of with. The contextlib from the standard library helps to make this easier.
Descriptors¶
Descriptors determine how attribute of object are accessed. The course uses examples to show how descriptors work and how they can be used to customize attribute access.
Metaclasses¶
Metaclasses offer a powerful way to change how classes in Python behave. Whíle being an advanced feature that should be used sparingly, it can provide interesting help for complex problems. The course shows how to apply metaclasses and gives examples where they can be useful.
Conventions¶
Python offers a lot of functionality out of the box where other languages need to use design patterns. These patterns are general solutions for certain types of problems.
Python offers what is called the “pythonic” way for solving a problem. The course presents of a few of these solutions:
wrapping instead of inheritance
dependency injections
factories
duck typing
monkey patching
callbacks
Good Style¶
Python is often described as an elegant language. Consistency is contributing to this. There are several recommendations and tools that help to check for them. The course has a closer look at the Python style guide (PEP8) and uses PyLint and pep8.py with examples. The participants are encouraged to bring their source code for style analysis.