Importing modules (the right way) | The Mechanics of CPython Pt 3

Опубликовано: 08 Июль 2026
на канале: Don't Use This Code • James Powell
221
14

Sign up for DUTC Weekly: https://mailchi.mp/dutc/ytweekly

LinkedIn:   / do-n-t-use-this-code  
Website: https://www.dontusethiscode.com/index...
Upcoming events: learning.dutc.io
Looking for training? Contact [email protected]


Let's talk about the mechanics behind the CPython interpreter to gain a better understanding of how we can design our code to make use of these mechanics, and to find ways to use this knowledge to better debug, investigate, and hot-patch our code.

This series is part of (More) Python Basics for Experts Session 2. In this series, we will look to answer the following questions:

What are exec and eval? How do they work? Should I ever use exec or eval in my code, or should these be strictly avoided?
What happens when I define a class? What purpose does type and do metaclasses serve? What is _new_ vs __init__? What is __prepare__? What is __set_name__?
What is super() and how does it work? How does single-argument super() reference the build-time class? What is name-mangling and where does it come up in practice?
What happens when I import a module? What is the difference between the different styles of module import (import … vs from … import …)?
What happens when I define a function? What is a closure? What are mutable default args?
What happens when I refer to variables in a defined function? How does scoping work in Python? Is Python pass-by-value, pass-by-reference, or something else entirely? What do the nonlocal and global keywords actually do?