zhalok rahman
zhalok rahman

Reputation: 13

I am not understanding the module structure and the functionalities of the import statement in python

Can anyone please help me understand the module structure of python and how the import works in python.

I wanted to use the linear_model of sklearn module in python but these two different codes are acting differently whereas they should have acted the same way. One is giving error and another one is working fine. Look at the code in this picture...

import sklearn as sk # gives error

from sklearn import linear_model # works fine

Upvotes: 1

Views: 45

Answers (1)

AKX
AKX

Reputation: 169194

import sklearn corresponds to importing sklearn/__init__.py.

That module does not re-export the subpackage sklearn.linear_model (sklearn/linear_model/__init__.py) as an attribute.

There's no reason why they should act the same way. Some packages do re-exporting, many (scikit-learn included) don't.

Upvotes: 6

Related Questions