Ukimiku Ukimiku - 1 month ago 13
Python Question

Correct terminology for Python imports

When I import third-party code in Python, what is the correct terminology to use? For example, in

from collections import Counter
, what do I call
collections
and what do I call
Counter
? Is
collections
a "module"? Then what to call
Counter
?

Answer
from collections import Counter

Here, collections is indeed a module.

Counter is a name. It can be a class, or function, or something else. It is simply a named thing, and you're bringing that name into your global namespace.

In this particular case, Counter is a class. We are hinted to this by the fact that it starts with a capital letter. But a look at the documentation tells us for certain that it is a class.

So we can say here that we are "importing the Counter class from the collections module".

Comments