When you execute story.apps.document import core , you tell the Python interpreter to match the story.apps.document description story.apps.document , import it, and then load the core variable from its namespace into your current one.
Because core is a file module that it has in its variables the namespaces defined in this file, for example, submit .
When you run from story import apps , you tell the Python interpreter to match the story description module, import it, and then load the apps variable from its namespace into your current one.
Since apps is a directory module, it has namespaces defined in its __init__.py and other modules in this directory in its variables. So apps knows about document , but knows nothing about the document core submodule.
FYI: The reason it sometimes confuses people is due to such things ...
It works well:
# File1 import story.apps.document story.apps.document.core()
Does not work:
# File2 import story story.apps.document.core()
For file1 Import works because the import operation tries to intelligently find things in the file system. The function call works because the document module has been imported and it is simply called story.apps.document .
For file2 calling a function does not work because there is nothing reasonable about the point operator, it just tries to access the attributes of the Python object - it knows nothing about file systems or modules.
source share