Elements of Metaprogramming

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

Get Expert Python Programming - Third Edition 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.