Why does import a.b.c run __init.py__ while from a.b.c import does not?

Viewed 52

Consider this simple Python package structure (where each __init__.py just prints the containing directory name and test.py prints 'test'):

a
├── __init__.py
└── b
    ├── __init__.py
    └── c
        ├── __init__.py
        └── test.py

Now if I import test two different ways I get completely different results:

>>> import a.b.c.test
a
b
c
test
>>> from a.b.c import test
>>>

Why are __init__.py files not run in the second case? Where is this documented?

0 Answers
Related