What Is The Default Binding To The `__import__` Attribute Of The Module `builtin`?
From Python in a Nutshell Custom Importers An advanced, rarely needed functionality that Python offers is the ability to change the semantics of some or all import and from
Solution 1:
Yes, that's a typo in the book. In Python 2 the same module is named
__builtin__
(nos
), in Python 3 it is namedbuiltins
.builtins.__import__
is a distinct function fromimportlib.__import__
. If you are going to rebindbuiltins.__import__
, save a reference.builtins.__import__
is implemented in C, and essentially calls the C-APIPyImport_ImportModuleLevelObject
function.importlib.__import__
is a pure-Python function. The goal ofimportlib
is to provide a pure-python implementation of the import machinery so it can be hacked on more easily, and this function is no exception.
Post a Comment for "What Is The Default Binding To The `__import__` Attribute Of The Module `builtin`?"