I have a following file structure:
mymodule/
__init__.py
mylib.py
test.py
File mymodule/__init__.py:
# mymodule/__init__.py
def call_me():
module = __import__('.mylib')
module.my_func()
File mymodule/mylib.py:
# mymodule/mylib.py
def my_func():
print("hi!")
File test.py:
# test.py
from mymodule import call_me
call_me()
If I run python3 test.py it fails with the error:
module = __import__('.mylib')
ImportError: No module named '.mylib'
I want to perform a relative import inside of call_me that equals to the static import from . import mylib. How can I do it?
def call_me(): from mymodule import mylib mylib.my_func()