PyCon Israel 2022

πŸ‡ΊπŸ‡Έ What happens when you import a module?
06-28, 11:30–12:20 (Asia/Jerusalem), Main Hall

We all "import" modules . But how does Python find and load modules, and making their definitions available? The answer is surprisingly complex. This talk walks you through the world of module importation, from load path, to finders and loaders.


Modules are a key feature of Python, allowing us to easily reuse our own code and take advantage of publicly available modules from PyPI. It's a rare program that doesn't include at least one "import" statement. But what actually happens when we import a module? How does Python find our file? How does it decide whether it should even try to find our module? And after it finds our module file, how does Python load it into memory, assigning to its attributes?

In this talk, I'll walk you through what happens when you "import" a module into Python. The mechanism is surprisingly complex, in no small part because it has to take so many possibilities into consideration. We'll talk about finders and loaders, and about the many ways in which you can customize the module-loading mechanism if you find a need to do so.

If you've ever imported a module, then this talk will pull back the curtain a bit, helping you to understand what's happening under the hood.


Session language –

English

Target audience –

Developers

Reuven M. Lerner is a full-time trainer, offering more than 30 courses
in Python and data science to companies around the world. Reuven is the
author of "Python Workout" and "Pandas Workout," both published with
Manning. His free, weekly "Better Developers" newsletter about Python
and software engineering has more than 25,000 subscribers. Reuven lives
in Modi'in, Israel with his wife and three children.