import function from a file in the same folder

Have you tried

import app.config as Config

It did the trick for me.


To import from the same folder you can do:

from .config import function_or_class_in_config_file

or to import the full config with the alias as you asked:

from ..app import config as Config

# imports all functions    
import config
# you invoke it this way
config.my_function()

or

# import specific function
from config import my_function
# you invoke it this way
my_function()

If the app.py is invoked not from the same folder you can do this:

# csfp - current_script_folder_path
csfp = os.path.abspath(os.path.dirname(__file__))
if csfp not in sys.path:
    sys.path.insert(0, csfp)
# import it and invoke it by one of the ways described above