The only component I need from pycountry is 'Languages'. I like to avoid importing anything more than needed, so I am tempted to do:
from pycountry import Languages
However, the only documented use I can find is:
import pycountry
Without knowing more, the only prudent option seems to be the documented route. As a module user, what else should I be aware of or consider?
FYI: I looked at In python, what are the pros and cons of importing a class vs. importing the class's module?, which had some good information but was focused on devs creating a module rather than using a module.
Update: I looked at Is import module
better coding style than from module import function
?. This has a wealth of good information, but I didn't see my fundamental misunderstanding addressed. I had assumed that from X import Y
only imported what I asked for, but it imports the whole module.
Update2:
PM 2Ring's comment that "FWIW, all forms of import actually import the entire module" caught me by surprise. Since I got a NameError: name 'pycountry' is not defined
on everything else in pycountry, I assumed nothing else was imported. Checking around (for example 'import module' vs. 'from module import function') I can see that 2ring is right and my assumptions were false.
Re: chepner's comment about being able to recognize the source when looking at my code. Since the first thing I would want to do is create my own alias langs = pycountry.languages
, I eliminate any advantage either import form had.
Combining the comments from 2Ring and chepner, there is no advantage to the from pycountry import Languages
form in my case and I shall use import pycountry
.
At this point I feel like my question has been fully answered.