When you do story.apps.document import core
, you're telling the Python interpreter to match a module of the description story.apps.document
, import it, then load the variable core
from its namespace into your current one.
Because core
is a file module it has in its namespace variables defined within that file e.g., submit
.
When you do from story import apps
, you're telling the Python interpreter to match a module of the description story
, import it, then load the variable apps
from its namespace into your current one.
Because apps
is a directory module it has within its namespace variables defined in its __init__.py
and other modules in that directory. So apps
knows about the document
but it doesn't know anything about document
's submodule core
.
FYI: The reason this sometimes confuses people is because of stuff like this...
Works just fine:
# File1
import story.apps.document
story.apps.document.core()
Doesn't work:
# File2
import story
story.apps.document.core() # <-- Looks like the same function call, but is an Error
For file1
, The import works because the the import
operation tries to intelligently find things on the filesystem. The function call works because the module document
was imported, and it is merely named story.apps.document
.
For file2
, the function call doesn't work because there's nothing intelligent about the dot operator, it merely attempts to access attributes on the Python object--it doesn't know anything about filesystems or modules.