© Sunil Kapil 2019
Sunil KapilClean Pythonhttps://doi.org/10.1007/978-1-4842-4878-2_5

5. Decorators and Context Managers

Sunil Kapil1 
(1)
Sunnyvale, CA, USA
 

Decorators and context managers are an advanced topic in Python, but they are useful in many real-world scenarios. Many popular libraries use decorators and context managers extensively to make their APIs and code cleaner. Initially, it might be a little tricky to understand decorators and context managers, but once you master them, they can make your code cleaner.

In this chapter, you will learn about decorators and context managers. You will also explore when these features can be useful while writing your next Python project.

Note

Decorators and context managers are advanced concepts in Python. ...

Get Clean Python: Elegant Coding in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.