Ukimiku Ukimiku - 1 year ago 107
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
and what do I call
? Is
a "module"? Then what to call

Answer Source
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".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download