Python 导入的正确术语

Correct terminology for Python imports

当我在 Python 中导入第三方代码时,正确的术语是什么?比如在from collections import Counter中,我怎么称呼collections,我又怎么称呼Countercollections 是 "module" 吗?那叫什么Counter?

from collections import Counter

这里,collections确实是一个模块

Counter 是一个 name。它可以是 class、函数或其他东西。它只是一个命名的 事物 ,您将该名称带入您的全局命名空间。

在这种特殊情况下,Counterclass。它以大写字母开头的事实暗示了这一点。但是看 the documentation 可以肯定地告诉我们它是 class.

所以我们可以在这里说我们是"importing the Counter class from the collections module"。

collections 是模块的名称,Counter 是从该模块导入的给定对象的名称。从英语你可以猜出是什么意思 from xxx import yyy.

语句 from collections import Counter 可以解释为 - collections 是您从中导入 class、函数或变量的模块 计数器