I am trying to import a file from the main directory using python. I tried several methods but no luck :(.
My file directory
|_ api
|__init__.py
|_api1.py
|_api2.py
|_api3.py
|_api4.py
|_api5.py
|_api6.py
|__init__.py
|_api.py
|_db_ops.py
Challenge
I am trying to import some methods of api.py
into api1.py
and api2.py
.
The solutions I have found were:
1. Add __ini__.py file
I have added them as you can see but did not work.
2. import using `import api`
did not worked rather throws an error **ModuleNotFoundError**
3. import using 'from . import api'
throws an error "cannot import from unknown module"
4. even tried to create a parent folder **test** and then tried with import test.apicall but still did not worked!
Any help.
Thanks