Understanding Decorators and Context Managers

Best Practice and Use Cases

Mike Müller

Best Practice Programming Python 3 Python Skills Python general

See in schedule: Mon, Jul 26, 09:30-11:00 CEST (90 min)

Python offers several advanced concepts. It is possible to write useful Python programs without them. But if you want to really understand how Python works and how to write pythonic programs, you should know how to write decorators and context managers.

The training covers them in detail, using code examples that will be immediately useful for your daily work. Carefully crafted exercises help you to experience the learned material. You will get detailed solutions for all exercises after the training.

The participants can follow all steps directly on their computers. There are exercises at the end of each unit providing ample opportunity to apply the freshly learned knowledge.

Decorators are a very useful technique to add functionality to existing functions and classes. The training uses examples such as caching, proxying, and checking of arguments to demonstrate how decorators can improve code readability and can simplify solutions. The training covers both function decorators and class decorators.

Context managers can help to make code more robust by ensuring that certain clean-up operations are guaranteed to happen. The training shows how to write your own context managers and how to apply them to different use cases. The training also covers the use of contextlib from the standard library.

Type: Training (180 mins); Python level: Intermediate; Domain level: Beginner


Mike Müller

Python Academy

Mike Müller has been using Python as his primary programming language since 1999. He is a Python trainer and the CEO at Python Academy (www.python-academy.com).

He teaches a wide variety of Python topics including "Introduction to Python", "Python for Scientists and Engineers", "Advanced Python" as well as "Optimization and Extensions of Python Programs".

He is the chairman of the Python Software Verband e.V., a PSF fellow, a PSF community service award holder, User Group co-founder. He chaired EuroSciPy 2008 and 2009, PyCon DE 2011 and 2012 as well as EuroPython 2014 in Berlin, Germany.