~/talk

What happens behind execution of an `import` statement?

Talkat PyConline AU 2020 · 2020-09-04..09-06· [python]
links:none on file
slides:none on file

Explains the step‑by‑step mechanics: a sys.modules check short‑circuits if present, otherwise the importer walks sys.meta_path calling find_spec until a finder returns a ModuleSpec containing a loader, then the loader runs create_module/exec_module and installs the module; missing specs raise ModuleNotFoundError, runtime load failures raise ImportError. Uses importlib base classes and implements a meta_path finder plus a loader that fetches .py files over HTTP with basic auth; the demo imports testproject.2.3 from a file server and executes its function successfully.

AI-written summary · about

  1. 0:00Start
  2. 3:31Regular packages
  3. 4:07Namespace packages - example
  4. 4:31Types of packages supported by default
  5. 5:03sys.modules
  6. 6:12Common use-cases of importlib
  7. 8:05Finders - examples
  8. 8:26Finders - function
  9. 9:09find_spec
  10. 9:32importing spam.ham
  11. 11:09an example of sys.meta_path and sys.path_hooks
  12. 11:27What are import hooks?
  13. 12:54Tasks of loaders
  14. 13:09example - loading
  15. 15:24chronological order
  16. 22:43What else can you do with import hooks?
  17. 23:13How have people used import hooks?
  18. 24:26sys.meta_path with virtual environment enabled
~/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.