模块“内置”的“__import__”属性的默认绑定是什么?

What is the default binding to the `__import__` attribute of the module `builtin`?

来自 Python 简而言之

Custom Importers

An advanced, rarely needed functionality that Python offers is the ability to change the semantics of some or all import and from statements.

Rebinding __import__

You can rebind the __import__ attribute of the module builtin to your own custom importer function—for example, one using the generic built-in-wrapping technique shown in “Python built-ins” on page 174.

  1. 在"You can rebind the __import__ attribute of the module builtin"中,"the module builtin"应该改为"the module builtins"吗?

  2. 是"the __import__ attribute of the module builtin"bound to importlib.__import__function by default吗?或者 "the module builtin" 是否提供绑定到其 __import__ 属性的默认实现?

  1. 是的,那是书中的错字。在 Python 2 中,相同的模块被命名为 __builtin__ (no s), in Python 3 it is named builtins.

  2. builtins.__import__ 是一个不同于 importlib.__import__ 的函数。如果您要重新绑定 builtins.__import__,请保存参考。