18.4 The importlib Package
The importlib package of the standard library implements the import behavior underlying the import statement. There are three basic uses for this package:
-
It contains the import_module function, which can be used to import a module or package without using the import statement. This is useful, for example, if the name of the module to be imported is available as a string.
-
It defines importers. Using these importers, it’s possible to intervene in the import process and thus modify the default behavior of the import statement.
-
The implementation of the import process is thus written in the Python language itself. In particular, this means that alternative Python interpreters don’t need to provide their own implementation; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access