Usage of import from different maps

My web system written with Python works very well. However, I am wondering if it is possible to import functions from different maps instead of using complicated function ‘importlib.import’.

That system has the base folder ‘WebSystem’ which has three main folders: ‘Base’, ‘Production’ and ‘Test’. Each main folder has several subfolders such as ‘css’, ‘htm’, ‘img’, ‘pyx’ and ‘txt’.

As for importing the specified function (for example, ‘fnx’ from the ‘WebSystem/…/pyx/fnx.py’ folder.

That system first tries to import that function from the main ‘Test’ folder. If not present, then from the ‘Production’ folder, otherwise from the ‘Base’ folder.

My import subroutine can be placed in one or more main folder in the subfolder ‘pyx’!

What would I actually have to do to execute that simple function ‘import’ in my import subroutine?

Hopefully this story clear enough for you to be able to help me.

Sounds like a perfect job for PYTHONPATH or sys.path.

Is it possible to do as follows:

for fnc in tableOfFunctionnames:
    if fnc is present in mainmap 'Test':
        Adapt sys.path 'WebSystem/Test/py'
        import fnc
    elif fnc is present in mainmap 'Production':
        Adapt sys.path 'WebSystem/Production/py'
        import fnc
    elif fnc is present in mainmap 'Base':
        Adapt sys.path 'WebSystem/Base/py'
        import fnc
    else:
        print 'Unknown function: ' + fnc

Yes, but please mention that partly pseudocode. (I have no idea what ‘mainmap’ means, but yes, you can conditionally add a directory to sys.path. I would advise removing it after the import.