Issue
Here is the directory and file as a tree:
.
├── my_dir
│ ├── a.py
│ └── b.py
└── outside.py
a.py
has only one function:
def my_func_a():
return "This is a test from a"
In b.py
I have imported the a.py
module and used its function inside another function:
from a import my_func_a
def my_func_b():
print(my_func_a())
return "This is a test from b"
Now, in outside.py
, when I am running the code, I am facing the ModuleNotFoundError
:
from my_dir import b
print(b.my_func_b())
the Error:
from a import my_func_a
ModuleNotFoundError: No module named 'a'
Solution
The importing should be as follows and it is working perfectly!
from .a import my_func_a
Answered By - Dolan Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.