views:

64

answers:

1

I am building a web app with this directory structure:

app/
    __init__.py
    config/
        __init__.py
        db_config.py
    models/
        __init__.py
        model.py
        datasources/
            __init__.py
            database.py
    ...
    ...

Every __init__.py file has

__all__ = ['', '', ...]

in it, listing the .py files that are in the same directory as it. So, app/__init__.py is empty, app/config/__init__.py has

__all__ = ['db_config']

, etc. in app/models/datasources/database.py, I cannot seem to import anything from app/config/db_config.py. I have tried

import app.config.db_config
import config.db_config
from app.config.db_config import *

but none of them has worked. If anyone has any ideas I'd really appreciate hearing them.

Also, I apologize if this is a duplicate question, but I wasn't sure exactly what to search for.

+2  A: 

import app.config.db_config is the best way (avoid non-absolute imports and never ever use import *), and for this to work the app directory should be in sys.path. If it is not, add the directory to you PYTHONPATH or move the project to somewhere this is the case.

Mike Graham