Daniela
Daniela

Reputation: 911

Python module has no attribute import error

I'm getting module has no attribute import error. I've done a bit of research and followed the answer in this post, but still doing something wrong.

I have the following project structure:

projectFolder
     __init__.py
     main.py
     subfolder
        __init__.py
        api.py
        models.py
        views.py

I would like to run a function contained in subfolder/api.py from main.py.

I've imported the file in subfolder/__init__.py as follows:

import projectFolder.subfolder.api

In main.py I've included this code:

from projectFolder import api

def function():
    get_api_function()

Upvotes: 0

Views: 1596

Answers (1)

AlanK
AlanK

Reputation: 9833

Try this import:

from subfolder.api import get_api_function

If the subfolder is on the python path it should work

Upvotes: 2

Related Questions