~/talk

What happens when you import a module?

Talkat PyCon Israel 2022 · 2022-06-28..06-29· [python]
slides:none on file

Explains exactly how import works: Python checks sys.modules cache, walks sys.meta_path finders (pathfinder, builtins, frozen), gets a ModuleSpec, uses the spec’s loader (or importlib.util) to create a module object and exec source into its __dict__; modules always execute on import and .pyc caching speeds later loads. Demonstrates pitfalls like local random.py shadowing stdlib, shows counts: interactive 79 modules, IPython 646, Jupyter 1020, and uses importlib.import_module and exec to implement loading.

AI-written summary · about

  1. 0:00Introduction to Reuben
  2. 1:02Why modules matter
  3. 2:51What is a module?
  4. 4:22Import statement basics
  5. 5:53Module objects and attributes
  6. 7:16Handling circular imports
  7. 8:26The module cache
  8. 10:42Pseudo code for imports
  9. 12:40Importing as aliases
  10. 14:11Global variables and namespaces
  11. 16:09From-import statement
  12. 17:15From-import pseudo code
  13. 18:51Risks of import star
  14. 19:55Functional importing
  15. 21:05How Python finds modules
  16. 24:35Modifying sys.path
  17. 26:39Finders and loaders
  18. 28:22Sys.metapath
  19. 30:46Built-in and compiled modules
  20. 32:37Module caching and pyc files
  21. 33:45Exec and module attributes
  22. 35:33Module execution process
  23. 37:20Dangers of eval and exec
  24. 39:22Populating the module namespace
  25. 41:59Import summary
  26. 43:33Packages and conclusion
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.