Change the future

Sunday 1:10 p.m.–1:40 p.m.

How Import Works

Brett Cannon

Audience level:
Intermediate
Category:
Core Python (Language, Stdlib)

Description

This talk will go over how the simple from sys import version turns out to be slightly complicated. The details of imports -- from how the import statement is interpreted to deciding what object to return -- will be discussed. While the talk will discuss things from the perspective of Python 3.3 (and thus importlib), the overall semantics will (mostly) apply to older versions of Python.

Abstract

Every program of substance in Python has at least a single import statement. It's what allows Python programmers to share code with one another. It has also been in the language for a very long time. This has led to somewhat complex semantics beyond the common case.

Starting in Python 3.3, Python's import system is based on importlib, which refactors and fully exposes Python's import system to the user for customization. This talk will explain how imports work from the perspective of importlib so people know not only how the overall system functions but also how they can change it to their benefit if desired.