Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Metaprogramming with Python

You're reading from   Metaprogramming with Python A programmer's guide to writing reusable code to build smarter applications

Arrow left icon
Product type Paperback
Published in Sep 2022
Publisher Packt
ISBN-13 9781838554651
Length 402 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sulekha Aloorravi Sulekha Aloorravi
Author Profile Icon Sulekha Aloorravi
Sulekha Aloorravi
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Preface 1. Part 1: Fundamentals – Introduction to Object-Oriented Python and Metaprogramming
2. Chapter 1: The Need for and Applications of Metaprogramming FREE CHAPTER 3. Chapter 2: Refresher of OOP Concepts in Python 4. Part 2: Deep Dive – Building Blocks of Metaprogramming I
5. Chapter 3: Understanding Decorators and their Applications 6. Chapter 4: Working with Metaclasses 7. Chapter 5: Understanding Introspection 8. Chapter 6: Implementing Reflection on Python Objects 9. Chapter 7: Understanding Generics and Typing 10. Chapter 8: Defining Templates for Algorithms 11. Part 3: Deep Dive – Building Blocks of Metaprogramming II
12. Chapter 9: Understanding Code through Abstract Syntax Tree 13. Chapter 10: Understanding Method Resolution Order of Inheritance 14. Chapter 11: Creating Dynamic Objects 15. Chapter 12: Applying GOF Design Patterns – Part 1 16. Chapter 13: Applying GOF Design Patterns – Part 2 17. Chapter 14: Generating Code from AST 18. Chapter 15: Implementing a Case Study 19. Chapter 16: Following Best Practices 20. Other Books You May Enjoy

Chapter 6: Implementing Reflection on Python Objects

In this chapter, we will look at reflection in Python 3 and understand how it is useful in metaprogramming. Reflection is a continuation of introspection, or it can be looked upon as a concept where we can make use of the information we learn from the introspection of properties or attributes of objects in Python and apply them to manipulate the objects, and so perform metaprogramming.

Why reflection? As we know from the previous chapter, introspection is an information-gathering process for Python objects. Reflection is the process of utilizing the information gathered from objects through introspection, and in turn, performing generic operations on them by manipulating them externally to perform metaprogramming.

Throughout this chapter, we will look at implementing reflection using each function that helped us introspect objects in the previous chapter and perform metaprogramming on the objects we use in our programs.

...
lock icon The rest of the chapter is locked
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Metaprogramming with Python
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime
Modal Close icon
Modal Close icon