How to import a project subfolder so that it is available once a project has been imported?
For example how to import the contents of project.tools so that after importing the project using import project, project.tools.common.function() is available?
project
|
|--tools
| |--__init__.py
| \--common.py
|
|--__init__.py
|--core.py
\--cli.py
I've tried the following:
from . import toolsinproject/__init__.pyandfrom . import *inproject/tools/__init.pywhich resulted in:ImportError: cannot import name 'tools'.from .tools import *inproject/__init__.pyandfrom . import *inproject/tools/__init.pywhich resulted in:ModuleNotFoundError: No module named 'project.tools'.from .tools import commoninproject/__init__.pyandfrom . import *inproject/tools/__init.pywhich resulted in:ModuleNotFoundError: No module named 'project.tools'.
Use
import toolsin your .py script directly. Then usetools.common.function()in the function call.When you place init.py in your folder, the folder becomes callable. Hence you can import that folder and its scripts directly into your scripts.