Dec-13-2019, 05:22 AM
I have a directory structure as below:
WD/
main.py
pkg1/
__init__.py
file1.py
file2.py
Now I would like to import pkg1 in my main python code "main.py". I use the following and it works OK
On the other hand, I don't get an error if I use the same syntax for importing a module
For example, if I use the following in __init__.py file
WD/
main.py
pkg1/
__init__.py
file1.py
file2.py
Now I would like to import pkg1 in my main python code "main.py". I use the following and it works OK
import pkg1but if I use, the following, i am getting an ImportError
from . import pkg1ImportError: cannot import name 'pkg1' from '__main__' (main.py)
On the other hand, I don't get an error if I use the same syntax for importing a module
For example, if I use the following in __init__.py file
from . import file1.py