Metaprogramming is one of the most complex and powerful approaches to programming in Python. Metaprogramming tools and techniques have evolved with Python; so, before we dive into this topic, it is important for you to know all the elements of modern Python syntax well. We discussed them in the two previous chapters. If you read them carefully, then you should know enough to fully understand the contents of this chapter.
In this chapter, we will explain what metaprogramming really is and present a few practical approaches to metaprogramming in Python.
In this chapter, we will cover the following topics:
- What is metaprogramming?
- Decorators
- Metaclasses
- Code generation