A memo on how to write __init__.py
when the structure is as follows.
root/
├ __init__.py
├ dir_a/
│ ├ __init__.py
│ └ test_a.py
(func_a is defined)
└ dir_b/
├ __init__.py
└ test_b.py
(func_b is defined)
After doing ʻimport root, I want to be able to call it with
root.func_a`. Since there was such a thing, I will realize this.
For root / __ init__.py
root/__init__.py
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from root.dir_a import *
from root.dir_b import *
For root / dir_a / __ init__.py
root/dir_a/__init__.py
from dir_a.test_a import *
Make root / dir_b / __ init__.py
similar to root /dir_a/__init__.py
root/dir_b/__init__.py
from dir_b.test_b import *
All you are doing is calling in sequence. The pass is troublesome.
Recommended Posts