简而言之,来自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 modulebuiltin
to your own custom importer function—for example, one using the generic built-in-wrapping technique shown in “Python built-ins” on page 174.
在“您可以重新绑定模块builtin
的__import__
属性”中,“模块builtin
”应该改为“模块builtins
”?
是模块builtin
的__import__
属性bound to ^{builtin
”是否提供绑定到其__import__
属性的默认实现?
是的,那是书中的错别字。在python2中,相同的模块被命名为^{} (no} 。
s
),在python3中,它被命名为^{builtins.__import__
是与importlib.__import__
不同的函数。如果要重新绑定builtins.__import__
,请保存一个引用。你知道吗builtins.__import__
是implemented in C,本质上调用C-API ^{importlib.__import__
是pure-Python function。importlib
的目标是提供导入机器的纯python实现,这样就可以更容易地对其进行黑客攻击,这个函数也不例外。相关问题 更多 >
编程相关推荐