对模块“builtin”的“import”属性的默认绑定是什么?

2024-09-30 05:18:41 发布

您现在位置:Python中文网/ 问答频道 /正文

简而言之,来自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. 在“您可以重新绑定模块builtin__import__属性”中,“模块builtin”应该改为“模块builtins”?

  2. 是模块builtin__import__属性bound to ^{}function by default?或者“模块builtin”是否提供绑定到其__import__属性的默认实现?


Tags: 模块ofthetoinimportan属性
1条回答
网友
1楼 · 发布于 2024-09-30 05:18:41
  1. 是的,那是书中的错别字。在python2中,相同的模块被命名为^{}(nos),在python3中,它被命名为^{}

  2. builtins.__import__是与importlib.__import__不同的函数。如果要重新绑定builtins.__import__,请保存一个引用。你知道吗

相关问题 更多 >

    热门问题