Python relative import local package module file All In One
$ tree
└── project
├── package1
│ ├── module1.py
│ └── module2.py
└── package2
├── __init__.py
├── module3.py
├── module4.py
└── subpackage1
└── module5.py
Recall the file contents:
package1/module2.py
contains a function, function1
.
package2/__init__.py
contains a class, class1
.
package2/subpackage1/module5.py
contains a function, function2
.
You can import class1
and function2
into the package2/module3.py
file this way:
# package2/module3.py
from . import class1
from .subpackage1.module5 import function2
https://realpython.com/absolute-vs-relative-python-imports/