This is very basic question which has a very extensive answer written by @Mark Roddy Use 'import module' or 'from module import'?
According to this answer there are pros and cons to each method but the result is equivalent and both work.
so doing:
import module
or
from module import foo
should work.
My Question:
Consider this example:
import distutils
print (distutils.util.strtobool('true'))
Which gives:
> Traceback (most recent call last): File "<stdin>", line 1, in
> <module> AttributeError: module 'distutils' has no attribute 'util'
And:
from distutils.util import strtobool
print (strtobool('true'))
Which gives following ouput:
1
So I'm confused. Both should work. Why Python generates an exception for the first approach?