Chapter 5: Understanding Introspection

In this chapter, we will look at introspection in Python 3 and understand how it is useful in metaprogramming. Introspection is a concept where we can learn about the properties or attributes of objects in Python during runtime using a suite of Python’s built-in methods.

Why introspection? Introspection is an information-gathering process for Python objects, and the information thus gathered can help in utilizing the objects to perform generic operations by manipulating them externally and, in turn, can help us in writing metaprograms.

Before we understand how to implement introspection, we will have a look at the built-in functions of Python that help in performing introspection. Throughout this chapter, ...

Get Metaprogramming with Python now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.